Caesar cipher: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 5,684: | Line 5,684: | ||
pack my box with five dozen liquor jugs |
pack my box with five dozen liquor jugs |
||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! RPL Code |
|||
! Comments |
|||
|- |
|||
| |
|||
≪ → a shift |
|||
≪ '''IF''' DUP a ≥ LAST 26 + < AND |
|||
'''THEN''' a - shift + 26 MOD a + '''END''' |
|||
≫ ≫ ‘'''Rotate'''’ STO |
|||
≪ → string shift |
|||
≪ "" 1 string SIZE '''FOR''' j |
|||
string j DUP SUB NUM |
|||
65 shift '''Rotate''' 90 shift '''Rotate''' |
|||
CHR + |
|||
'''NEXT''' |
|||
≫ ''''CESAR'''' STO |
|||
| |
|||
''( m a shift -- n )'' |
|||
if m in [a, a+26[ |
|||
then shift it modulo 26 |
|||
''( string shift -- string )'' |
|||
Scan input string |
|||
extract jth ASCII code |
|||
shift if [A..Z] or [a..z] |
|||
back to character |
|||
|} |
|||
The following line of command delivers what is required: |
|||
"The quick brown fox jumped over the lazy dogs" '''CESAR''' |
|||
{{out}} |
|||
<pre> |
|||
1: "Esp bftnv mczhy qzi ufxapo zgpc esp wlkj ozrd" |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<syntaxhighlight lang="ruby">class String |
<syntaxhighlight lang="ruby">class String |
||
Line 5,698: | Line 5,738: | ||
decrypted = encypted.caesar_cipher(-3) |
decrypted = encypted.caesar_cipher(-3) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
<syntaxhighlight lang="runbasic">input "Gimme a ofset:";ofst ' set any offset you like |
<syntaxhighlight lang="runbasic">input "Gimme a ofset:";ofst ' set any offset you like |