Rot-13: Difference between revisions

18,829 bytes added ,  1 month ago
 
(33 intermediate revisions by 22 users not shown)
Line 132:
.end
save "rot-13", rot13, end</syntaxhighlight>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program rot1364.s */
/************************************/
/* Constantes */
/************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
.equ STRINGSIZE, 500
 
//.include "../../ficmacros64.inc"
/************************************/
/* Initialized data */
/************************************/
.data
szMessString: .asciz "String :\n"
szMessEncrip: .asciz "\nEncrypted :\n"
szMessDecrip: .asciz "\nDecrypted :\n"
szString1: .asciz "{NOWHERE! abcd xyz 1234}"
 
szCarriageReturn: .asciz "\n"
/************************************/
/* UnInitialized data */
/************************************/
.bss
szString2: .skip STRINGSIZE
szString3: .skip STRINGSIZE
/************************************/
/* code section */
/************************************/
.text
.global main
main:
 
ldr x0,qAdrszMessString // display message
bl affichageMess
ldr x0,qAdrszString1 // display string
bl affichageMess
ldr x0,qAdrszString1
ldr x1,qAdrszString2
bl encryptRot13
ldr x0,qAdrszMessEncrip
bl affichageMess
ldr x0,qAdrszString2 // display string
bl affichageMess
ldr x0,qAdrszString2
ldr x1,qAdrszString3
bl decryptRot13
ldr x0,qAdrszMessDecrip
bl affichageMess
ldr x0,qAdrszString3 // display string
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
100: // standard end of the program
mov x0, #0 // return code
mov x8,EXIT
svc 0 // perform system call
qAdrszMessString: .quad szMessString
qAdrszMessDecrip: .quad szMessDecrip
qAdrszMessEncrip: .quad szMessEncrip
qAdrszString1: .quad szString1
qAdrszString2: .quad szString2
qAdrszString3: .quad szString3
qAdrszCarriageReturn: .quad szCarriageReturn
/******************************************************************/
/* encrypt strings */
/******************************************************************/
/* x0 contains the address of the string1 */
/* x1 contains the address of the encrypted string */
encryptRot13:
stp x3,lr,[sp,-16]! // save registers
stp x4,x5,[sp,-16]! // save registers
mov x3,#0 // counter byte string 1
mov x2,#13 // rot characters number
1:
ldrb w4,[x0,x3] // load byte string 1
cmp w4,#0 // zero final ?
bne 2f
strb w4,[x1,x3]
mov x0,x3
b 100f
2:
cmp w4,#65 // < A ?
bge 3f
strb w4,[x1,x3]
add x3,x3,#1
b 1b // and loop
3:
cmp x4,#90 // > Z
bgt 4f
add x4,x4,x2 // add key
cmp x4,#90 // > Z
sub x5,x4,26
csel x4,x5,x4,gt
strb w4,[x1,x3]
add x3,x3,#1
b 1b
4:
cmp x4,#97 // < a ?
bge 5f
strb w4,[x1,x3]
add x3,x3,#1
b 1b
5:
cmp x4,#122 //> z
ble 6f
strb w4,[x1,x3]
add x3,x3,#1
b 1b
6:
add x4,x4,x2
cmp x4,#122
sub x5,x4,26
csel x4,x5,x4,gt
strb w4,[x1,x3]
add x3,x3,#1
b 1b
 
100:
ldp x4,x5,[sp],16 // restaur registers
ldp x3,lr,[sp],16 // restaur registers
ret
/******************************************************************/
/* decrypt strings */
/******************************************************************/
/* x0 contains the address of the encrypted string1 */
/* x1 contains the address of the decrypted string */
decryptRot13:
stp x3,lr,[sp,-16]! // save registers
stp x4,x5,[sp,-16]! // save registers
mov x3,#0 // counter byte string 1
mov x2,#13 // rot characters number
1:
ldrb w4,[x0,x3] // load byte string 1
cmp w4,#0 // zero final ?
bne 2f
strb w4,[x1,x3]
mov x0,x3
b 100f
2:
cmp x4,#65 // < A ?
bge 3f
strb w4,[x1,x3]
add x3,x3,#1
b 1b // and loop
3:
cmp x4,#90 // > Z
bgt 4f
sub x4,x4,x2 // substract key
cmp x4,#65 // < A
add x5,x4,26
csel x4,x5,x4,lt
strb w4,[x1,x3]
add x3,x3,#1
b 1b
4:
cmp x4,#97 // < a ?
bge 5f
strb w4,[x1,x3]
add x3,x3,#1
b 1b
5:
cmp x4,#122 // > z
ble 6f
strb w4,[x1,x3]
add x3,x3,#1
b 1b
6:
sub x4,x4,x2 // substract key
cmp x4,#97 // < a
add x5,x4,26
csel x4,x5,x4,lt
strb w4,[x1,x3]
add x3,x3,#1
b 1b
 
100:
ldp x4,x5,[sp],16 // restaur registers
ldp x3,lr,[sp],16 // restaur registers
ret
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeARM64.inc"
</syntaxhighlight>
{{Out}}
<pre>
String :
{NOWHERE! abcd xyz 1234}
Encrypted :
{ABJURER! nopq klm 1234}
Decrypted :
{NOWHERE! abcd xyz 1234}
</pre>
 
=={{header|ACL2}}==
Line 343 ⟶ 542:
<syntaxhighlight lang="applesoftbasic">100HOME:INPUT"ENTER A STRING:";S$:FORL=1TOLEN(S$):I$=MID$(S$,L,1):LC=(ASC(I$)>95)*32:C$=CHR$(ASC(I$)-LC):IFC$>="A"ANDC$<="Z"THENC$=CHR$(ASC(C$)+13):C$=CHR$(ASC(C$)-26*(C$>"Z")):I$=CHR$(ASC(C$)+LC)
110A$=A$+I$:NEXT:PRINTA$</syntaxhighlight>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program rot13.s */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes */
/************************************/
.include "../constantes.inc"
 
.equ STRINGSIZE, 500
/************************************/
/* Initialized data */
/************************************/
.data
szMessString: .asciz "String :\n"
szMessEncrip: .asciz "\nEncrypted :\n"
szMessDecrip: .asciz "\nDecrypted :\n"
szString1: .asciz "{NOWHERE! abcd xyz 1234}"
 
szCarriageReturn: .asciz "\n"
/************************************/
/* UnInitialized data */
/************************************/
.bss
szString2: .skip STRINGSIZE
szString3: .skip STRINGSIZE
/************************************/
/* code section */
/************************************/
.text
.global main
main:
 
ldr r0,iAdrszMessString @ display message
bl affichageMess
ldr r0,iAdrszString1 @ display string
bl affichageMess
ldr r0,iAdrszString1
ldr r1,iAdrszString2
bl encryptRot13
ldr r0,iAdrszMessEncrip
bl affichageMess
ldr r0,iAdrszString2 @ display string
bl affichageMess
ldr r0,iAdrszString2
ldr r1,iAdrszString3
bl decryptRot13
ldr r0,iAdrszMessDecrip
bl affichageMess
ldr r0,iAdrszString3 @ display string
bl affichageMess
ldr r0,iAdrszCarriageReturn
bl affichageMess
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc 0 @ perform system call
iAdrszMessString: .int szMessString
iAdrszMessDecrip: .int szMessDecrip
iAdrszMessEncrip: .int szMessEncrip
iAdrszString1: .int szString1
iAdrszString2: .int szString2
iAdrszString3: .int szString3
iAdrszCarriageReturn: .int szCarriageReturn
/******************************************************************/
/* encrypt strings */
/******************************************************************/
/* r0 contains the address of the string1 */
/* r1 contains the address of the encrypted string */
encryptRot13:
push {r3,r4,lr} @ save registers
mov r3,#0 @ counter byte string 1
mov r2,#13 @ rot characters number
1:
ldrb r4,[r0,r3] @ load byte string 1
cmp r4,#0 @ zero final ?
streqb r4,[r1,r3]
moveq r0,r3
beq 100f
cmp r4,#65 @ < A ?
strltb r4,[r1,r3]
addlt r3,#1
blt 1b
cmp r4,#90 @ > Z
bgt 2f
add r4,r2 @ add key
cmp r4,#90 @ > Z
subgt r4,#26
strb r4,[r1,r3]
add r3,#1
b 1b
2:
cmp r4,#97 @ < a ?
strltb r4,[r1,r3]
addlt r3,#1
blt 1b
cmp r4,#122 @> z
strgtb r4,[r1,r3]
addgt r3,#1
bgt 1b
add r4,r2
cmp r4,#122
subgt r4,#26
strb r4,[r1,r3]
add r3,#1
b 1b
 
100:
pop {r3,r4,lr} @ restaur registers
bx lr @ return
/******************************************************************/
/* decrypt strings */
/******************************************************************/
/* r0 contains the address of the encrypted string1 */
/* r1 contains the address of the decrypted string */
decryptRot13:
push {r3,r4,lr} @ save registers
mov r3,#0 @ counter byte string 1
mov r2,#13 @ rot characters number
1:
ldrb r4,[r0,r3] @ load byte string 1
cmp r4,#0 @ zero final ?
streqb r4,[r1,r3]
moveq r0,r3
beq 100f
cmp r4,#65 @ < A ?
strltb r4,[r1,r3]
addlt r3,#1
blt 1b
cmp r4,#90 @ > Z
bgt 2f
sub r4,r2 @ substract key
cmp r4,#65 @ < A
addlt r4,#26
strb r4,[r1,r3]
add r3,#1
b 1b
2:
cmp r4,#97 @ < a ?
strltb r4,[r1,r3]
addlt r3,#1
blt 1b
cmp r4,#122 @ > z
strgtb r4,[r1,r3]
addgt r3,#1
bgt 1b
sub r4,r2 @ substract key
cmp r4,#97 @ < a
addlt r4,#26
strb r4,[r1,r3]
add r3,#1
b 1b
 
100:
pop {r3,r4,lr} @ restaur registers
bx lr @ return
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language ARM assembly*/
.include "../affichage.inc"
 
 
</syntaxhighlight>
{{Out}}
<pre>
String :
{NOWHERE! abcd xyz 1234}
Encrypted :
{ABJURER! nopq klm 1234}
Decrypted :
{NOWHERE! abcd xyz 1234}
</pre>
 
=={{header|Arturo}}==
Line 593 ⟶ 967:
PRINT "After decoding : "; rot13$(s$)
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Rot-13"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
dec$ = ""
TYPE$ = "cleartext "
ctext$ = ""
iOffset = 13 'offset assumed to be 13 - uncomment line 11 to change
 
PRINT "For decrypt enter " + "<d> " + " -- else press enter > ";
dec$ = INLINE$("")
PRINT
 
IF LCASE$(dec$) = "d" THEN
iOffset = 26 - iOffset
TYPE$ = "ciphertext "
END IF
 
PRINT "Enter " + TYPE$; '' + "> ";
cad$ = UCASE$(INLINE$("> "))
 
FOR i = 1 TO LEN(cad$)
iTemp = ASC(MID$(cad$,i,1))
IF iTemp > 64 AND iTemp < 91 THEN
iTemp = ((iTemp - 65) + iOffset) MOD 26
PRINT CHR$(iTemp + 65);
END IF
NEXT i
END FUNCTION
END PROGRAM</syntaxhighlight>
 
=={{header|BASIC256}}==
Line 738 ⟶ 1,147:
: 0 `#v_@v-6-7< >
, < <+6+7 <<v</syntaxhighlight>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">chars ← ⥊ "AaNn" +⌜ ↕13
 
Rot13 ← {𝕨 ⊣⌾((𝕩=52)⊸/) ⊏⟜chars 52|26+𝕩}⟜(chars⊸⊐)</syntaxhighlight>
Test:
<syntaxhighlight lang="bqn">Rot13 "Abcdefghijklm:Nopqrstuvwxyz_123 aBCDEFGHIJKLM-nOPQRSTUVWXYZ."</syntaxhighlight>
{{out}}
<pre>"Nopqrstuvwxyz:Abcdefghijklm_123 nOPQRSTUVWXYZ-aBCDEFGHIJKLM."</pre>
 
=={{header|Burlesque}}==
Line 806 ⟶ 1,224:
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using System;
using System;
using System.IO;
using System.Linq;
using System.Text;
 
class Program
{
static char Rot13(char c)
{
if ('a' <= c && c <= 'm' || 'A' <= c && c <= 'M')
{
return (char)(c + 13);
}
if ('n' <= c && c <= 'z' || 'N' <= c && c <= 'Z')
{
return (char)(c - 13);
}
return c;
}
 
class Program {
static string Rot13(string s)
private static char shift(char c) {
{
return new stringc.ToString(s).SelectToLower(Rot13).ToArrayFirst()); switch {
>= 'a' and <= 'm' => (char)(c + 13),
>= 'n' and <= 'z' => (char)(c - 13),
var _ => c
};
}
 
static string Rot13(string s) => new string(s.Select(c => shift(c)).ToArray());
 
 
static void Main(string[] args)
static void Main(string[] args) {
{
foreach (var file in args.Where(file => File.Exists(file))) {
{
Console.WriteLine(Rot13(File.ReadAllText(file)));
}
if (!args.Any()) {
{
Console.WriteLine(Rot13(Console.In.ReadToEnd()));
}
Line 1,052 ⟶ 1,460:
 
=={{header|COBOL}}==
{{Works with|COBOL-85}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
Strict COBOL-85 implementation.
<syntaxhighlight lang="cobol">FORMAT IDENTIFICATION DIVISION.
PROGRAM-ID. rot-13.
 
DATA DIVISION.
LOCAL-STORAGELINKAGE SECTION.
7877 STRin-LENGTHstr VALUE PIC X(100).
77 out-str PIC X(100).
78 normal-lower VALUE "abcdefghijklmnopqrstuvwxyz".
78 rot13-lower VALUE "nopqrstuvwxyzabcdefghijklm".
 
PROCEDURE DIVISION USING BY REFERENCE in-str, out-str.
78 normal-upper VALUE "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
78 rot13-upper VALUEMOVE "NOPQRSTUVWXYZABCDEFGHIJKLM".in-str TO out-str
INSPECT out-str
CONVERTING "abcdefghijklmnopqrstuvwxyz"
TO "nopqrstuvwxyzabcdefghijklm"
INSPECT out-str
CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
TO "NOPQRSTUVWXYZABCDEFGHIJKLM"
EXIT PROGRAM.
 
END PROGRAM rot-13.</syntaxhighlight>
LINKAGE SECTION.
{{Works with|COBOL 2002}}
01 in-str PIC X(STR-LENGTH).
A more modern version, with a user-defined function and compile-time constants.
01 out-str PIC X(STR-LENGTH).
<syntaxhighlight lang="cobolfree">IDENTIFICATION DIVISION.
FUNCTION-ID. rot-13.
 
DATA DIVISION.
PROCEDURE DIVISION USING VALUE in-str, REFERENCE out-str.
LOCAL-STORAGE SECTION.
MOVE in-str TO out-str
01 STR-LENGTH CONSTANT AS 100.
01 normal-lower CONSTANT AS "abcdefghijklmnopqrstuvwxyz".
01 rot13-lower CONSTANT AS "nopqrstuvwxyzabcdefghijklm".
01 normal-upper CONSTANT AS "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
01 rot13-upper CONSTANT AS "NOPQRSTUVWXYZABCDEFGHIJKLM".
LINKAGE SECTION.
77 in-str PICTURE IS X(STR-LENGTH).
77 out-str PICTURE IS X(STR-LENGTH).
 
PROCEDURE DIVISION USING in-str, RETURNING out-str.
INSPECT out-str CONVERTING normal-lower TO rot13-lower
MOVE INSPECT outin-str CONVERTING normal-upper TO rot13out-upperstr
INSPECT out-str CONVERTING normal-lower TO rot13-lower
INSPECT out-str CONVERTING normal-upper TO rot13-upper
GOBACK.
 
END FUNCTION rot-13.</syntaxhighlight>
GOBACK
.</syntaxhighlight>
 
=={{header|Commodore BASIC}}==
Line 1,284 ⟶ 1,711:
"Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt!".rot13().writeln();
}</syntaxhighlight>
 
=={{header|Dart}}==
{{trans|Swift}}
<syntaxhighlight lang="Dart">
String rot13char(int charCode) {
if ((charCode >= 'A'.codeUnitAt(0) && charCode <= 'M'.codeUnitAt(0)) ||
(charCode >= 'a'.codeUnitAt(0) && charCode <= 'm'.codeUnitAt(0))) {
return String.fromCharCode(charCode + 13);
} else if ((charCode >= 'N'.codeUnitAt(0) && charCode <= 'Z'.codeUnitAt(0)) ||
(charCode >= 'n'.codeUnitAt(0) && charCode <= 'z'.codeUnitAt(0))) {
return String.fromCharCode(charCode - 13);
} else {
return String.fromCharCode(charCode);
}
}
 
String rot13(String str) {
return String.fromCharCodes(str.runes.map((rune) {
return rot13char(rune).codeUnitAt(0);
}));
}
 
void main() {
print(rot13("The quick brown fox jumps over the lazy dog"));
}
</syntaxhighlight>
{{out}}
<pre>
Gur dhvpx oebja sbk whzcf bire gur ynml qbt
 
</pre>
 
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
Line 1,377 ⟶ 1,836:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
procfunc$ rot13 string$ . encodedStringstr$ .
for c$ in strchars str$
encodedString$ = ""
for i = 1c to= lenstrcode stringc$
codeif c >= strcode65 substrand string$c i<= 190
if code > c = (c + 13 - 65) andmod code26 <=+ 9065
elif c >= encodedCode97 =and codec +<= 13122
ifc encodedCode= >(c 90+ 13 - 97) mod 26 + 97
encodedCode = 64 + encodedCode - 90
.
elif code >= 97 and code <= 122
encodedCode = code + 13
if encodedCode > 122
encodedCode = 96 + encodedCode - 122
.
else
encodedCode = code
.
encodedStringenc$ &= strchar encodedCodec
.
return enc$
.
enc$ = rot13 "Rosetta Code"
#
print enc$
call rot13 "Rosetta Code" result$
print resultrot13 enc$
</syntaxhighlight>
{{out}}
<pre>Ebfrggn Pbqr</pre>
 
=={{header|Elena}}==
ELENA 46.x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 1,428 ⟶ 1,877:
string convert(string s)
= s.selectBy::(ch => rotConvertor.convert(ch)).summarize(new StringWriter());
}
Line 1,791 ⟶ 2,240:
 
PAUSE
</syntaxhighlight>
 
=={{header|Fennel}}==
{{trans|Lua}}
 
<syntaxhighlight lang="fennel">
(fn rot13 [s]
(let [a :ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
b :NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm]
(s:gsub :%a #(b:sub (a:find $)))))
</syntaxhighlight>
 
Line 2,211 ⟶ 2,670:
WRITE(ClipBoard, Name) txt, cod ! txt=abc? XYZ!; cod=nop? KLM!;
END</syntaxhighlight>
 
=={{header|Haxe}}==
<syntaxhighlight lang="haxe">
public static function rot13(input: String): String {
var buf = new StringBuf();
for (charInt in new haxe.iterators.StringIterator(input)) {
if (charInt >= 0x41 && charInt <= 0x4d || charInt >= 0x61 && charInt <= 0x6d)
charInt += 13;
else if (charInt >= 0x4e && charInt <= 0x5a || charInt >= 0x6e && charInt <= 0x7a)
charInt -= 13;
buf.addChar(charInt);
}
return buf.toString();
}
</syntaxhighlight>
 
=={{header|Hy}}==
<syntaxhighlight lang="hy">#!/usr/bin/env hy
(require hyrule [defmain])
 
(setv lowers (lfor *x* (range 26)
(chr (+ *x* (ord "a"))))) ; generate latin lower 26 chars
(setv uppers (list (map str.upper lowers))) ; and the upper case
(setv lowers (list (map ord lowers))) ; convert to unicode codepoints
(setv uppers (list (map ord uppers)))
(setv translations ; a dictionary with from->to
(dict (zip ; codepoint mapping
(+ lowers uppers)
(+ (cut lowers 13 None)
(cut lowers 0 13)
(cut uppers 13 None)
(cut uppers 0 13)))))
 
(defn rot13 [string]
(return (.translate string translations)))
 
(defmain []
(import fileinput)
(for [*line* (fileinput.input)]
(print (rot13 *line*) :end "")))
</syntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 2,233 ⟶ 2,733:
* the setup exploits the ordered cset variables &lcase and &ucase coercing them into strings
* the rot13 mapping string is then aggregated with strings taken by offsetting into double length values to avoid unnecessary and messy rotation
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(function ROT-13-char ch
(let x (char-code ch)
x- (or (< 109 x 123) (< 77 x 91)))
(if (or (< 96 x 123) (< 64 x 91))
(char-code ((x- - +) x 13))
ch))
 
(function ROT-13 text
(.. str (map ROT-13-char text)))
 
(ROT-13 "The Quick Brown Fox Jumps Over The Lazy Dog!")
;returns "Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt!"</syntaxhighlight>
 
=={{header|IS-BASIC}}==
Line 3,563 ⟶ 4,077:
 
val rot13 = String.map rot13char</syntaxhighlight>
 
Helper function:
 
<syntaxhighlight lang="sml">fun rot13stdin () =
case (TextIO.inputLine TextIO.stdIn)
of NONE => ()
| SOME(s) => (print (rot13 s); rot13stdin ());
</syntaxhighlight>
 
==={{header|mLite}}===
Reads text file from stdin to list of lines, encodes and prints lines of encoding to stdout.
Line 4,846 ⟶ 5,369:
put .trans: $abc => $abc».rotate(13) for lines</syntaxhighlight>
 
{{in}}
Input:
<pre>Rosetta Code</pre>
 
{{out}}
Output:
<pre>Ebfrggn Pbqr</pre>
 
As a one-liner:
 
<syntaxhighlight lang=console>$ raku -pe '.=trans: {$_ => $_».rotate(13)}({[$_».uc, @$_]}("a".."z"))'</syntaxhighlight>
 
=={{header|RapidQ}}==
Line 5,203 ⟶ 5,730:
Restored : The quick brown fox jumps over the lazy red dog.
</pre>
 
Still a third approach makes use of S-BASIC's awkward (and poorly documented) XLATE function, which transforms each character in the input string by using its ASCII value as an index into the translation string.
<syntaxhighlight lang = "basic">
function rot13(s = string) = string
var tr = string:127
rem - set up translation table
tr = space$(31) + " !" + chr(34) + "#$%&'()*+,-./0123456789" + \
":;<=>?@NOPQRSTUVWXYZABCDEFGHIJKLM[\]^_`" + \
"nopqrstuvwxyzabcdefghijklm{|}~"
end = xlate(s,tr)
 
rem - test the function
 
var plain, encrypted = string
 
plain = "The quick brown fox jumps over the lazy dog."
print "Plain text: "; plain
encrypted = rot13(plain)
print "Encrypted : "; encrypted
print "Restored : "; rot13(encrypted)
 
end
</syntaxhighlight>
 
=={{header|S-lang}}==
Line 5,352 ⟶ 5,902:
<syntaxhighlight lang="ruby"># Returns a copy of 's' with rot13 encoding.
func rot13(s) {
s.tr('A-Za-z', 'N-ZA-Mn-za-m');
}
 
# Perform rot13 on standard input.
STDIN.each { |line| printsay rot13(line) }</syntaxhighlight>
 
=={{header|Simula}}==
<syntaxhighlight lang="simula"> TEXT PROCEDURE ROT13(INP); TEXT INP;
Line 5,665 ⟶ 6,216:
rot13("Shall Not Perish")
Funyy Abg Crevfu</syntaxhighlight>
 
=={{header|Stringle}}==
<syntaxhighlight lang="stringle">a "The quick brown fox jumps over the lazy dog."
b "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
c b
#@c 78
#\c 52
#a
b %.a d " " b
b %.a #d .a
b %.a e c
b %.a #e #d
b %.a a .\e :a
f f .a
a :a
#a
$ f</syntaxhighlight>
{{out}}
Gur dhvpx oebja sbk whzcf bire gur ynml qbt.
 
=={{header|Swift}}==
Line 5,842 ⟶ 6,412:
 
rot = ~command.files; * contents:= ~contents; * * -:~& -- ^p(~&,rep13~&zyC)~~ ~=`A-~ letters</syntaxhighlight>
 
=={{header|Uxntal}}==
<syntaxhighlight lang="Uxntal">( in-place rot13, null terminated string )
@rot13 ( addr* -: addr* )
DUP2
&loop
LDAk ?{ POP2 JMP2r } STH2k
LDAk #df AND DUP #41 LTH SWP #5a GTH ORA
STH LDAk STHr
?{
DUP #df AND
#0d ADD
DUP #5a GTH #1a MUL SUB
SWP #20 AND ORA
}
STH2r STA INC2
!&loop</syntaxhighlight>
 
=={{header|Vala}}==
Line 6,215 ⟶ 6,802:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var rot13 = Fn.new { |s|
var bytes = s.bytes.toList
for (i in 0...bytes.count) {
Line 6,353 ⟶ 6,940:
</pre>
 
 
=={{header|YAMLScript}}==
<syntaxhighlight lang="yaml">
!yamlscript/v0
 
s =: set(nil).into('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
m =: drop(26 s).concat(take(26 s)).zipmap(s _)
 
defn main(s):
say: map(\(m %1 %1) s).apply(str _)
</syntaxhighlight>
 
=={{header|Zig}}==
 
<syntaxhighlight lang="zig">
{{Works with|Zig|0.11.x}}
// Warning: modifies the buffer in-place (returns pointer to in)
{{Works with|Zig|0.12.0-dev.1643+91329ce94}}
fn rot13(in: [] u8) []u8 {
 
for (in) |*c| {
<syntaxhighlight lang="zig">const std = @import("std");
var d : u8 = c.*;
 
var x : u8 = d;
pub const Rot13 = struct {
x = if (@subWithOverflow(u8, d | 32, 97, &x) ) x else x;
pub fn if char(xch: <u8) 26)u8 {
return x =switch (x + 13ch) % 26 + 65 + (d & 32);{
c'a'.*..'m', 'A'...'M' => |c| c + x;13,
} 'n'...'z', 'N'...'Z' => |c| c - 13,
else => |c| c,
};
}
return in;
}
 
/// Caller owns returned memory.
const msg: [:0] const u8 =
pub fn slice(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]u8 {
\\Lbh xabj vg vf tbvat gb or n onq qnl
const output = try allocator.alloc(u8, input.len);
\\ jura gur yrggref va lbhe nycunorg fbhc
errdefer allocator.free(output);
\\ fcryy Q-V-F-N-F-G-R-E.
;
 
for (input, output) |input_ch, *output_ch| {
// need to copy the const string to a buffer
output_ch.* = char(input_ch);
// before we can modify it in-place
}
//https://zig.news/kristoff/what-s-a-string-literal-in-zig-31e9
 
return output;
var buf: [500]u8 = undefined;
fn assignStr(out: []u8, str: [:0]const u8) void {
for (str) |c, i| {
out[i] = c;
}
};
out[str.len] = 0;
}
 
pub fn main() error{OutOfMemory}!void {
const print = @import("std").debug.print;
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .{};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
 
const message_input =
pub fn main() void {
\\@@@111@@@ Lbh xabj vg vf tbvat gb or n onq qnl
assignStr(&buf, msg);
\\ jura gur yrggref va lbhe nycunorg fbhc
print("rot13={s}\n",.{rot13(&buf)});
\\ fcryy Q-V-F-N-F-G-R-E.
}
;
</syntaxhighlight>
const message_decoded = try Rot13.slice(allocator, message_input);
defer allocator.free(message_decoded);
 
std.debug.print(
\\{s}
\\=== Decoded to ===
\\{s}
\\
, .{
message_input,
message_decoded,
});
 
std.debug.print("\n", .{});
 
const message_encoded = try Rot13.slice(allocator, message_decoded);
defer allocator.free(message_encoded);
 
std.debug.print(
\\{s}
\\=== Encoded to ===
\\{s}
\\
, .{
message_decoded,
message_encoded,
});
}</syntaxhighlight>
 
{{out}}
<pre>
@@@111@@@ Lbh xabj vg vf tbvat gb or n onq qnl
jura gur yrggref va lbhe nycunorg fbhc
fcryy Q-V-F-N-F-G-R-E.
=== Decoded to ===
@@@111@@@ You know it is going to be a bad day
when the letters in your alphabet soup
spell D-I-S-A-S-T-E-R.
 
@@@111@@@ You know it is going to be a bad day
when the letters in your alphabet soup
spell D-I-S-A-S-T-E-R.
=== Encoded to ===
@@@111@@@ Lbh xabj vg vf tbvat gb or n onq qnl
jura gur yrggref va lbhe nycunorg fbhc
fcryy Q-V-F-N-F-G-R-E.
 
</pre>
 
=={{header|zkl}}==
62

edits