Chaocipher: Difference between revisions

1,577 bytes added ,  3 months ago
Added Easylang
(Added Easylang)
 
(2 intermediate revisions by 2 users not shown)
Line 1,186:
readln;
end.</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
proc index c$ . a$[] ind .
for ind = 1 to len a$[]
if a$[ind] = c$
return
.
.
ind = 0
.
left$ = "HXUCZVAMDSLKPEFJRIGTWOBNYQ"
right$ = "PTLNBQDEOYSFAVZKGJRIHWXUMC"
#
func$ chao txt$ mode .
left$[] = strchars left$
right$[] = strchars right$
len tmp$[] 26
for c$ in strchars txt$
# print strjoin left$[] & " " & strjoin right$[]
if mode = 1
index c$ right$[] ind
if ind = 0
return ""
.
r$ &= left$[ind]
else
index c$ left$[] ind
if ind = 0
print c$
return ""
.
r$ &= right$[ind]
.
# permute left
for j = ind to 26
tmp$[j - ind + 1] = left$[j]
.
for j = 1 to ind - 1
tmp$[26 - ind + j + 1] = left$[j]
.
h$ = tmp$[2]
for j = 3 to 14
tmp$[j - 1] = tmp$[j]
.
tmp$[14] = h$
swap tmp$[] left$[]
#
# permute right
for j = ind to 26
tmp$[j - ind + 1] = right$[j]
.
for j = 1 to ind - 1
tmp$[26 - ind + j + 1] = right$[j]
.
h$ = tmp$[1]
for j = 2 to 26
tmp$[j - 1] = tmp$[j]
.
tmp$[26] = h$
h$ = tmp$[3]
for j = 4 to 14
tmp$[j - 1] = tmp$[j]
.
tmp$[14] = h$
swap tmp$[] right$[]
.
return r$
.
h$ = chao "WELLDONEISBETTERTHANWELLSAID" 1
print h$
print chao h$ 2
</syntaxhighlight>
{{out}}
<pre>
OAHQHCNYNXTSZJRRHJBYHQKSOUJY
WELLDONEISBETTERTHANWELLSAID
</pre>
 
=={{header|EMal}}==
Line 1,377 ⟶ 1,455:
'''Solution'''
 
[[File:Fōrmulæ - Chaocipher 01a01.png]]
 
'''Test 1.''' Encryption
Line 1,383 ⟶ 1,461:
[[File:Fōrmulæ - Chaocipher 02.png]]
 
[[File:Fōrmulæ - Chaocipher 03a03.png]]
 
'''Test 2.''' Decryption
Line 1,389 ⟶ 1,467:
[[File:Fōrmulæ - Chaocipher 04.png]]
 
[[File:Fōrmulæ - Chaocipher 05a05.png]]
 
=={{header|FreeBASIC}}==
Line 3,709 ⟶ 3,787:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">class Chao {
static encrypt { 0 }
static decrypt { 1 }
2,060

edits