Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
30
Task/Chaocipher/Julia/chaocipher.julia
Normal file
30
Task/Chaocipher/Julia/chaocipher.julia
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
const leftalphabet = "HXUCZVAMDSLKPEFJRIGTWOBNYQ"
|
||||
const rightalphabet = "PTLNBQDEOYSFAVZKGJRIHWXUMC"
|
||||
|
||||
function chacocoding(text, encoding, verbose=false)
|
||||
left, right = Vector{Char}(leftalphabet), Vector{Char}(rightalphabet)
|
||||
len, coded = length(text), similar(Vector{Char}(text))
|
||||
for i in 1:len
|
||||
verbose && println(String(left), " ", String(right))
|
||||
n = indexin(text[i], encoding ? right : left)[1]
|
||||
coded[i] = encoding ? left[n] : right[n]
|
||||
if i < len
|
||||
left .= circshift(left, -n + 1)
|
||||
left[2:14] .= circshift(left[2:14], -1)
|
||||
right .= circshift(right, -n)
|
||||
right[3:14] .= circshift(right[3:14], -1)
|
||||
end
|
||||
end
|
||||
String(coded)
|
||||
end
|
||||
|
||||
function testchacocipher(txt)
|
||||
println("The original plaintext is: $txt")
|
||||
println("\nThe left and right alphabets for each character during encryption are:")
|
||||
encoded = chacocoding(txt, true, true)
|
||||
println("\nThe encoded ciphertext is: $encoded")
|
||||
decoded = chacocoding(encoded, false)
|
||||
println("\nDecoded, the recovered plaintext is: $decoded")
|
||||
end
|
||||
|
||||
testchacocipher("WELLDONEISBETTERTHANWELLSAID")
|
||||
Loading…
Add table
Add a link
Reference in a new issue