Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,21 +1,21 @@
|
|||
import std.stdio, std.string;
|
||||
|
||||
string encrypt(in string txt, in string key) pure
|
||||
string encrypt(in string txt, in string key) pure @safe
|
||||
in {
|
||||
assert(key.removechars("^A-Z") == key);
|
||||
} body {
|
||||
string res;
|
||||
foreach (immutable i, immutable c; toUpper(txt).removechars("^A-Z"))
|
||||
foreach (immutable i, immutable c; txt.toUpper.removechars("^A-Z"))
|
||||
res ~= (c + key[i % $] - 2 * 'A') % 26 + 'A';
|
||||
return res;
|
||||
}
|
||||
|
||||
string decrypt(in string txt, in string key) pure
|
||||
string decrypt(in string txt, in string key) pure @safe
|
||||
in {
|
||||
assert(key.removechars("^A-Z") == key);
|
||||
} body {
|
||||
string res;
|
||||
foreach (immutable i, immutable c; toUpper(txt).removechars("^A-Z"))
|
||||
foreach (immutable i, immutable c; txt.toUpper.removechars("^A-Z"))
|
||||
res ~= (c - key[i % $] + 26) % 26 + 'A';
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
import std.stdio, std.range, std.ascii, std.string, std.algorithm,
|
||||
std.conv;
|
||||
|
||||
enum mod = (in int m, in int n) pure nothrow => ((m % n) + n) % n;
|
||||
enum mod = (in int m, in int n) pure nothrow @safe @nogc =>
|
||||
((m % n) + n) % n;
|
||||
|
||||
enum _s2v = (in string s) pure /*nothrow*/ =>
|
||||
enum _s2v = (in string s) pure /*nothrow*/ @safe =>
|
||||
s.toUpper.removechars("^A-Z").map!q{ a - 'A' };
|
||||
|
||||
string _v2s(R)(R v) pure /*nothrow*/ {
|
||||
string _v2s(R)(R v) pure /*nothrow*/ @safe {
|
||||
return v.map!(x => uppercase[x.mod(26)]).text;
|
||||
}
|
||||
|
||||
enum encrypt = (in string txt, in string key) pure /*nothrow*/ =>
|
||||
enum encrypt = (in string txt, in string key) pure /*nothrow*/ @safe =>
|
||||
txt._s2v.zip(key._s2v.cycle).map!q{ a[0] + a[1] }._v2s;
|
||||
|
||||
enum decrypt = (in string txt, in string key) pure /*nothrow*/ =>
|
||||
enum decrypt = (in string txt, in string key) pure /*nothrow*/ @safe =>
|
||||
txt._s2v.zip(key._s2v.cycle).map!q{ a[0] - a[1] }._v2s;
|
||||
|
||||
void main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue