first of all I'm reasonably new to Python. I'll try to explain this as best I can! I'm currently making an Encryption/Decryption program which encrypts and decrpyts a file, everything works fine, no errors given. Only when I check the newly decrypted file to the original in a Hex editor, very few but some bytes have not been decrpyted correctly. The only places I can see this happening is with any 'FF' byte is now a '00' byte in the decrypted file. I can't work out why this is happening, code is below:
def shift_byte(x):
if(ord(x) == 0):
return (ord(x))
elif(ord(x) == shiftrange):
v1 = (ord(x) + shift)
return v1
else:
return ((ord(x) + shift) % 255)
That is the encryption, just a simple shift cipher, this is the decryption from another file:
def shift_byte(x):
if(x == 0):
return (x)
elif(x == shiftrange):
v1 = x - shift
return v1
else:
return ((x - shift) % 255)
My only thoughts are that it is something to do with this line:
return ((x - shift) % 255)
Is there something wrong here? Thanks.
ord(x)be a range? Shouldn'tord(x)be within a range? Why not always use the modulus operator?