Rot-13: Difference between revisions
→{{header|Fennel}}: shorten
(Added XBasic) |
(→{{header|Fennel}}: shorten) |
||
(15 intermediate revisions by 12 users not shown) | |||
Line 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 1,702 ⟶ 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,795 ⟶ 1,836:
=={{header|EasyLang}}==
<syntaxhighlight
func$ rot13 str$ .
for c$ in strchars str$
if
elif c >=
.
.
return
.
print enc$
print rot13 enc$
</syntaxhighlight>
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 1,844 ⟶ 1,877:
string convert(string s)
= s.selectBy::(ch => rotConvertor.convert(ch)).summarize(new StringWriter());
}
Line 2,207 ⟶ 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,627 ⟶ 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}}==
Line 5,844 ⟶ 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|
=={{header|Simula}}==
<syntaxhighlight lang="simula"> TEXT PROCEDURE ROT13(INP); TEXT INP;
Line 6,157 ⟶ 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 6,334 ⟶ 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,707 ⟶ 6,802:
=={{header|Wren}}==
<syntaxhighlight lang="
var bytes = s.bytes.toList
for (i in 0...bytes.count) {
Line 6,845 ⟶ 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}}==
{{Works with|Zig|0.11.x}}
{{Works with|Zig|0.12.0-dev.1643+91329ce94}}
<syntaxhighlight lang="zig">const std = @import("std");
pub const Rot13 = struct {
pub fn
return
else => |c| c,
};
}
/// Caller owns returned memory.
pub fn slice(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]u8 {
const output = try allocator.alloc(u8, input.len);
errdefer allocator.free(output);
for (input, output) |input_ch, *output_ch| {
output_ch.* = char(input_ch);
}
return output;
}
};
pub fn main() error{OutOfMemory}!void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .{};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const message_input =
\\@@@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.
;
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}}==
|