Caesar cipher: Difference between revisions

Zig added
(Zig added)
Line 7,607:
 
You are encouraged to solve this task according to the task description, using any language you may know.</pre>
=={{header|Zig}}==
<syntaxhighlight lang="zig">
const std = @import("std");
const stdout = @import("std").io.getStdOut().writer();
 
pub fn rot(txt: []u8, key: u8) void {
for (txt, 0..txt.len) |c, i| {
if (std.ascii.isLower(c)) {
txt[i] = (c - 'a' + key) % 26 + 'a';
} else if (std.ascii.isUpper(c)) {
txt[i] = (c - 'A' + key) % 26 + 'A';
}
}
}
 
pub fn main() !void {
const key = 3;
var txt = "The five boxing wizards jump quickly".*;
 
try stdout.print("Original: {s}\n", .{txt});
rot(&txt, key);
try stdout.print("Encrypted: {s}\n", .{txt});
rot(&txt, 26 - key);
try stdout.print("Decrypted: {s}\n", .{txt});
}
</syntaxhighlight>
{{out}}
<pre>
Original: The five boxing wizards jump quickly
Encrypted: Wkh ilyh eralqj zlcdugv mxps txlfnob
Decrypted: The five boxing wizards jump quickly
</pre>
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">fcn caesarCodec(str,n,encode=True){
Line 7,627 ⟶ 7,660:
decoded = The five boxing wizards jump quickly
</pre>
 
=={{header|zonnon}}==
<syntaxhighlight lang="zonnon">
19

edits