48 lines
1.5 KiB
Plaintext
48 lines
1.5 KiB
Plaintext
begin enum
|
|
_encrypt
|
|
_decrypt
|
|
end enum
|
|
|
|
local fn chaocipher(orig as str255, action as byte, show as bool) as str255
|
|
str255 leftStr, rightStr, out
|
|
short i, index
|
|
leftStr = "HXUCZVAMDSLKPEFJRIGTWOBNYQ"
|
|
rightStr = "PTLNBQDEOYSFAVZKGJRIHWXUMC"
|
|
orig = ucase$(orig)
|
|
out[0] = orig[0]
|
|
|
|
if show then print:print,"The left and right alphabets during encryption are:":print
|
|
|
|
for i = 1 to orig[0]
|
|
if show then print ,leftStr,,rightStr
|
|
if action == _encrypt
|
|
index = instr$(0, rightStr, mid$(orig, i, 1))
|
|
out[i] = leftStr[index]
|
|
else
|
|
index = instr$(0, leftStr, mid$(orig, i, 1))
|
|
out[i] = rightStr[index]
|
|
end if
|
|
|
|
//leftStr permutation
|
|
leftStr = mid$(leftStr, index) + left$(leftStr, index-1)
|
|
leftStr = left$(leftStr, 1) + mid$(leftStr, 3, 12) + mid$(leftStr, 2, 1) + mid$(leftStr, 15)
|
|
|
|
//rightStr permutation
|
|
rightStr = mid$(rightStr, index+1) + left$(rightStr, index-1) + mid$(rightStr, index, 1)
|
|
rightStr = left$(rightStr, 2) + mid$(rightStr, 4, 11) + mid$(rightStr, 3, 1) + mid$(rightStr, 15)
|
|
next
|
|
|
|
end fn = out
|
|
|
|
|
|
str255 original, encrypted, decrypted
|
|
original = "WellDoneIsBetterThanWellSaid"
|
|
|
|
window 1, @"Chaocipher", ( 0, 0, 475, 550 )
|
|
print : print ,"The original text is: """; original; """"
|
|
encrypted = fn chaocipher(original, _encrypt, yes)
|
|
print : print ,"The encrypted text is: """; encrypted; """"
|
|
decrypted = fn chaocipher(encrypted, _decrypt, no)
|
|
print : print ,"The decrypted text is: """; decrypted; """"
|
|
handleevents
|