From e300cbfb41ee369c7531af984715912ea1cb0c41 Mon Sep 17 00:00:00 2001 From: rtang09 <49603415+rtang09@users.noreply.github.com> Date: Wed, 4 Oct 2023 21:45:55 -0700 Subject: [PATCH 1/9] Add files via upload --- hashes/fletcher16.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 hashes/fletcher16.py diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py new file mode 100644 index 000000000000..e4bc07407cc8 --- /dev/null +++ b/hashes/fletcher16.py @@ -0,0 +1,24 @@ +''' +The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John G. Fletcher (1934–2012) at Lawrence Livermore Labs in the late 1970s.[1] The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques. + +Source: https://en.wikipedia.org/wiki/Fletcher%27s_checksum +''' + +def fletcher16(data): + ''' + Loops through every character in the data and adds to two sums + + fletcher16('hello world') == 6752 + ''' + sum1 = 0 + sum2 = 0 + for character in data: + sum1 = (sum1+character)%255 + sum2 = (sum1+sum2)%255 + return (sum2 << 8) | sum1 + + +if __name__ == "__main__": + text = input("Enter a text: ") + stuffs = bytes(text, "ascii") + print(fletcher16(stuffs)) \ No newline at end of file From ac7cdba8e50186ad37d4748d9f46f42b498fd105 Mon Sep 17 00:00:00 2001 From: rtang09 <49603415+rtang09@users.noreply.github.com> Date: Wed, 4 Oct 2023 21:50:37 -0700 Subject: [PATCH 2/9] Update fletcher16.py --- hashes/fletcher16.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py index e4bc07407cc8..d825a9b564e5 100644 --- a/hashes/fletcher16.py +++ b/hashes/fletcher16.py @@ -4,12 +4,12 @@ Source: https://en.wikipedia.org/wiki/Fletcher%27s_checksum ''' -def fletcher16(data): +def fletcher16(text: str) -> int: ''' Loops through every character in the data and adds to two sums - fletcher16('hello world') == 6752 ''' + data = bytes(text, "ascii") sum1 = 0 sum2 = 0 for character in data: @@ -20,5 +20,4 @@ def fletcher16(data): if __name__ == "__main__": text = input("Enter a text: ") - stuffs = bytes(text, "ascii") - print(fletcher16(stuffs)) \ No newline at end of file + print(fletcher16(text)) From 79feadf848642fab37b0b611561225f8b068d87f Mon Sep 17 00:00:00 2001 From: rtang09 <49603415+rtang09@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:17:58 -0700 Subject: [PATCH 3/9] Update fletcher16.py --- hashes/fletcher16.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py index d825a9b564e5..19d794b6b1bd 100644 --- a/hashes/fletcher16.py +++ b/hashes/fletcher16.py @@ -7,7 +7,15 @@ def fletcher16(text: str) -> int: ''' Loops through every character in the data and adds to two sums - fletcher16('hello world') == 6752 + + + + >>> fletcher16('hello world') + 6752 + >>> fletcher16('onethousandfourhundredthirtyfour') + 28347 + >>> fletcher16('The quick brown fox jumps over the lazy dog.') + 5655 ''' data = bytes(text, "ascii") sum1 = 0 @@ -19,5 +27,5 @@ def fletcher16(text: str) -> int: if __name__ == "__main__": - text = input("Enter a text: ") - print(fletcher16(text)) + import doctest + doctest.testmod() From f4427ba11e5d5d22c014822a438a4d1b2178efb8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 05:24:57 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hashes/fletcher16.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py index 19d794b6b1bd..eeb7eafeeafb 100644 --- a/hashes/fletcher16.py +++ b/hashes/fletcher16.py @@ -1,11 +1,12 @@ -''' +""" The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John G. Fletcher (1934–2012) at Lawrence Livermore Labs in the late 1970s.[1] The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques. Source: https://en.wikipedia.org/wiki/Fletcher%27s_checksum -''' +""" + def fletcher16(text: str) -> int: - ''' + """ Loops through every character in the data and adds to two sums @@ -16,16 +17,17 @@ def fletcher16(text: str) -> int: 28347 >>> fletcher16('The quick brown fox jumps over the lazy dog.') 5655 - ''' + """ data = bytes(text, "ascii") sum1 = 0 sum2 = 0 for character in data: - sum1 = (sum1+character)%255 - sum2 = (sum1+sum2)%255 + sum1 = (sum1 + character) % 255 + sum2 = (sum1 + sum2) % 255 return (sum2 << 8) | sum1 if __name__ == "__main__": import doctest + doctest.testmod() From b4ec72f4c875084af41cb5713dd8f82274b9370f Mon Sep 17 00:00:00 2001 From: rtang09 <49603415+rtang09@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:27:01 -0700 Subject: [PATCH 5/9] Update fletcher16.py --- hashes/fletcher16.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py index eeb7eafeeafb..c4444efd665e 100644 --- a/hashes/fletcher16.py +++ b/hashes/fletcher16.py @@ -1,12 +1,15 @@ -""" -The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John G. Fletcher (1934–2012) at Lawrence Livermore Labs in the late 1970s.[1] The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques. +''' +The Fletcher checksum is an algorithm for computing a position-dependent checksum +devised by John G. Fletcher (1934–2012) at Lawrence Livermore Labs in the late 1970s.[1] +The objective of the Fletcher checksum was to provide error-detection properties approaching +those of a cyclic redundancy check but with the lower computational effort associated with +summation techniques. Source: https://en.wikipedia.org/wiki/Fletcher%27s_checksum -""" - +''' def fletcher16(text: str) -> int: - """ + ''' Loops through every character in the data and adds to two sums @@ -17,17 +20,16 @@ def fletcher16(text: str) -> int: 28347 >>> fletcher16('The quick brown fox jumps over the lazy dog.') 5655 - """ + ''' data = bytes(text, "ascii") sum1 = 0 sum2 = 0 for character in data: - sum1 = (sum1 + character) % 255 - sum2 = (sum1 + sum2) % 255 + sum1 = (sum1+character)%255 + sum2 = (sum1+sum2)%255 return (sum2 << 8) | sum1 if __name__ == "__main__": import doctest - doctest.testmod() From d141feed7a54afc80e91c4c721bf622b06a43565 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 05:27:34 +0000 Subject: [PATCH 6/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hashes/fletcher16.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py index c4444efd665e..ec481f38ea0e 100644 --- a/hashes/fletcher16.py +++ b/hashes/fletcher16.py @@ -1,4 +1,4 @@ -''' +""" The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John G. Fletcher (1934–2012) at Lawrence Livermore Labs in the late 1970s.[1] The objective of the Fletcher checksum was to provide error-detection properties approaching @@ -6,10 +6,11 @@ summation techniques. Source: https://en.wikipedia.org/wiki/Fletcher%27s_checksum -''' +""" + def fletcher16(text: str) -> int: - ''' + """ Loops through every character in the data and adds to two sums @@ -20,16 +21,17 @@ def fletcher16(text: str) -> int: 28347 >>> fletcher16('The quick brown fox jumps over the lazy dog.') 5655 - ''' + """ data = bytes(text, "ascii") sum1 = 0 sum2 = 0 for character in data: - sum1 = (sum1+character)%255 - sum2 = (sum1+sum2)%255 + sum1 = (sum1 + character) % 255 + sum2 = (sum1 + sum2) % 255 return (sum2 << 8) | sum1 if __name__ == "__main__": import doctest + doctest.testmod() From 45e79a788e6d21b778b9858bcbc0849085230b62 Mon Sep 17 00:00:00 2001 From: rtang09 <49603415+rtang09@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:28:52 -0700 Subject: [PATCH 7/9] Update fletcher16.py --- hashes/fletcher16.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py index ec481f38ea0e..dd8ae1685a77 100644 --- a/hashes/fletcher16.py +++ b/hashes/fletcher16.py @@ -1,16 +1,16 @@ -""" -The Fletcher checksum is an algorithm for computing a position-dependent checksum -devised by John G. Fletcher (1934–2012) at Lawrence Livermore Labs in the late 1970s.[1] -The objective of the Fletcher checksum was to provide error-detection properties approaching -those of a cyclic redundancy check but with the lower computational effort associated with -summation techniques. +''' +The Fletcher checksum is an algorithm for computing a position-dependent +checksum devised by John G. Fletcher (1934–2012) at Lawrence Livermore Labs +in the late 1970s.[1] The objective of the Fletcher checksum was to +provide error-detection properties approaching those of a cyclic +redundancy check but with the lower computational effort associated +with summation techniques. Source: https://en.wikipedia.org/wiki/Fletcher%27s_checksum -""" - +''' def fletcher16(text: str) -> int: - """ + ''' Loops through every character in the data and adds to two sums @@ -21,17 +21,16 @@ def fletcher16(text: str) -> int: 28347 >>> fletcher16('The quick brown fox jumps over the lazy dog.') 5655 - """ + ''' data = bytes(text, "ascii") sum1 = 0 sum2 = 0 for character in data: - sum1 = (sum1 + character) % 255 - sum2 = (sum1 + sum2) % 255 + sum1 = (sum1+character)%255 + sum2 = (sum1+sum2)%255 return (sum2 << 8) | sum1 if __name__ == "__main__": import doctest - doctest.testmod() From a28d3c72bf686e428a0ab6ccb2d40442af57e5b7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 05:29:25 +0000 Subject: [PATCH 8/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hashes/fletcher16.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py index dd8ae1685a77..0609e4d91f5c 100644 --- a/hashes/fletcher16.py +++ b/hashes/fletcher16.py @@ -1,4 +1,4 @@ -''' +""" The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John G. Fletcher (1934–2012) at Lawrence Livermore Labs in the late 1970s.[1] The objective of the Fletcher checksum was to @@ -7,10 +7,11 @@ with summation techniques. Source: https://en.wikipedia.org/wiki/Fletcher%27s_checksum -''' +""" + def fletcher16(text: str) -> int: - ''' + """ Loops through every character in the data and adds to two sums @@ -21,16 +22,17 @@ def fletcher16(text: str) -> int: 28347 >>> fletcher16('The quick brown fox jumps over the lazy dog.') 5655 - ''' + """ data = bytes(text, "ascii") sum1 = 0 sum2 = 0 for character in data: - sum1 = (sum1+character)%255 - sum2 = (sum1+sum2)%255 + sum1 = (sum1 + character) % 255 + sum2 = (sum1 + sum2) % 255 return (sum2 << 8) | sum1 if __name__ == "__main__": import doctest + doctest.testmod() From 114e415a71217f18280f4291ff0eeda9cede348d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 5 Oct 2023 08:07:46 +0200 Subject: [PATCH 9/9] Update fletcher16.py --- hashes/fletcher16.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hashes/fletcher16.py b/hashes/fletcher16.py index 0609e4d91f5c..7c23c98d72c5 100644 --- a/hashes/fletcher16.py +++ b/hashes/fletcher16.py @@ -12,9 +12,7 @@ def fletcher16(text: str) -> int: """ - Loops through every character in the data and adds to two sums - - + Loop through every character in the data and add to two sums. >>> fletcher16('hello world') 6752