Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Caesar-cipher/D/caesar-cipher-2.d
Normal file
20
Task/Caesar-cipher/D/caesar-cipher-2.d
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import std.stdio, std.ascii;
|
||||
|
||||
void inplaceRot(char[] txt, in int key) pure nothrow {
|
||||
foreach (ref c; txt) {
|
||||
if (isLower(c))
|
||||
c = (c - 'a' + key) % 26 + 'a';
|
||||
else if (isUpper(c))
|
||||
c = (c - 'A' + key) % 26 + 'A';
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
enum key = 3;
|
||||
auto txt = "The five boxing wizards jump quickly".dup;
|
||||
writeln("Original: ", txt);
|
||||
txt.inplaceRot(key);
|
||||
writeln("Encrypted: ", txt);
|
||||
txt.inplaceRot(26 - key);
|
||||
writeln("Decrypted: ", txt);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue