Group.6
A = ['1','2']
L = 0
R = 0
def Fletcher(A,n):
global L,R
for i in range(n):
R = (R+int(A[i])) % 255
L = (L+R) % 255
print hex((L << 8) | R) #'<<' mean binary left shift and '|' mean binary OR
def CheckBytes(L,R):
tempR = 255 - ((R+L) % 255)
tempL = 255 - ((R+tempR) % 255)
print hex(tempR),hex(tempL)
#Checksum
Fletcher(A,len(A))
#Checkbytes
CheckBytes(L,R)
#check sum
print (L*65536)+R
Implement in python
Example calculation of the Fletcher-16 checksum :
Weaknesses
The Fletcher checksum cannot distinguish between blocks of all 0 bits and blocks of all 1 bits
For example:
0x0000 (0) have checksum as 0xff (255)
0xFFFF (65535) also have checksum as 0xff (255)
A = 'abcd123456' #data
L = 0
R = 1 #
def Adler(A,n):
global L,R
for i in range(n):
R = (R+ord(A[i])) % 65521 #2^16 = 65536 and 65521 is prime number that close to 2^16
L = (L+R) % 65521
Adler(A,len(A))
#check sum
print (L*65536)+R
Implement in python
Example calculation of the Adler-32 checksum :
Weaknesses