Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,22 @@
import std.stdio, std.traits;
S rot(S)(in S s, in int key) pure nothrow @safe
if (isSomeString!S) {
auto res = s.dup;
foreach (immutable i, ref c; res) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26 + 'A');
}
return res;
}
void main() @safe {
enum key = 3;
immutable txt = "The five boxing wizards jump quickly";
writeln("Original: ", txt);
writeln("Encrypted: ", txt.rot(key));
writeln("Decrypted: ", txt.rot(key).rot(26 - key));
}

View 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);
}

View file

@ -0,0 +1,17 @@
import std.stdio, std.ascii, std.string, std.algorithm;
string rot(in string s, in int key) pure nothrow @safe {
auto uppr = uppercase.dup.representation;
bringToFront(uppr[0 .. key], uppr[key .. $]);
auto lowr = lowercase.dup.representation;
bringToFront(lowr[0 .. key], lowr[key .. $]);
return s.translate(makeTrans(letters, assumeUTF(uppr ~ lowr)));
}
void main() {
enum key = 3;
immutable txt = "The five boxing wizards jump quickly";
writeln("Original: ", txt);
writeln("Encrypted: ", txt.rot(key));
writeln("Decrypted: ", txt.rot(key).rot(26 - key));
}