Vigenère cipher: Difference between revisions

(Added Kotlin)
Line 720:
}</lang>
The output is the same.
 
=={{header|Elena}}==
{{trans|C#}}
ELENA 3.2.1 :
<lang elena>import system'text.
import system'math.
import system'routines.
import extensions.
 
class VCipher
{
literal encrypt(LiteralValue txt, LiteralValue pw, IntNumber d)
[
var output := TextBuilder new.
int pwi := 0.
literal $pw := pw upperCase.
txt upperCase; forEach(:t)
[
if(t >= $65)
[
int tmp := t toInt - 65 + d * ($pw[pwi] toInt - 65).
if (tmp < 0)
[
tmp += 26
].
output write((65 + tmp mod:26) toChar).
pwi += 1.
if (pwi == $pw length) [ pwi := 0 ]
]
].
^ output literal
]
}
 
program =
[
var v := VCipher new.
var s0 := "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!".
var pw := "VIGENERECIPHER".
console printLine(s0,'newLine,pw,'newLine).
var s1 := v encrypt(s0, pw, 1).
console printLine("Encrypted:",s1).
s1 := v encrypt(s1, "VIGENERECIPHER", -1).
console printLine("Decrypted:",s1).
console printLine("Press any key to continue..").
console readKey.
].</lang>
{{out}}
<pre>
Beware the Jabberwock, my son! The jaws that bite, the claws that catch!
VIGENERECIPHER
 
Encrypted:WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
Decrypted:BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH
Press any key to continue..
</pre>
 
=={{header|Elixir}}==
Anonymous user