introduced digraph reversal in case of same row/column
This commit is contained in:
@@ -83,8 +83,9 @@ def ipfencrypt(msg:str, key:str):
|
||||
elif y1 == y2: # same row: get the coords to the right
|
||||
x1 = (x1 + 1) % pfsize
|
||||
x2 = (x2 + 1) % pfsize
|
||||
enc.append(getgridchar(kg, x1, y1))
|
||||
# swap the ciphertext character
|
||||
enc.append(getgridchar(kg, x2, y2))
|
||||
enc.append(getgridchar(kg, x1, y1))
|
||||
# generate a random prefix
|
||||
preflen = (len(key) % 10) + 1
|
||||
prefix = ''
|
||||
@@ -112,14 +113,14 @@ def ipfdecrypt(enc:str, key:str):
|
||||
msg.append(getgridchar(kg, x2, y1))
|
||||
else:
|
||||
if x1 == x2: # same column: get the coords above
|
||||
y1 -= 1
|
||||
if y1 < 0:
|
||||
y1 += pfsize
|
||||
y2 -= 1
|
||||
if y2 < 0:
|
||||
y2 += pfsize
|
||||
elif y1 == y2: # same row: get the coords to the left
|
||||
x1 -= 1
|
||||
if x1 < 0:
|
||||
x1 += pfsize
|
||||
msg.append(getgridchar(kg, x1, y1))
|
||||
x2 -= 1
|
||||
if x2 < 0:
|
||||
x2 += pfsize
|
||||
msg.append(getgridchar(kg, x2, y2))
|
||||
# finalize the decrypted message
|
||||
return ''.join(msg).strip()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user