How to resolve the algorithm Chaocipher step by step in the FutureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chaocipher step by step in the FutureBasic programming language
Table of Contents
Problem Statement
The Chaocipher was invented by J.F.Byrne in 1918 and, although simple by modern cryptographic standards, does not appear to have been broken until the algorithm was finally disclosed by his family in 2010. The algorithm is described in this paper by M.Rubin in 2010 and there is a C# implementation here.
Code the algorithm in your language and test that it works with the plaintext 'WELLDONEISBETTERTHANWELLSAID' used in the paper itself.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Chaocipher step by step in the FutureBasic programming language
Source code in the futurebasic programming language
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
You may also check:How to resolve the algorithm Runtime evaluation/In an environment step by step in the Julia programming language
You may also check:How to resolve the algorithm Extreme floating point values step by step in the Go programming language
You may also check:How to resolve the algorithm Empty program step by step in the Io programming language
You may also check:How to resolve the algorithm Execute Computer/Zero step by step in the PL/M programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the Common Lisp programming language