Vigenère cipher: Difference between revisions

Content added Content deleted
(Updated second D entry)
Line 544: Line 544:
s.toUpper.removechars("^A-Z").map!q{ a - 'A' };
s.toUpper.removechars("^A-Z").map!q{ a - 'A' };


string _v2s(R)(R v) /*pure nothrow*/ {
string _v2s(R)(R v) pure /*nothrow*/ {
return v.map!(x => uppercase[x.mod(26)]).text;
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*/ =>
txt._s2v.zip(key._s2v.cycle).map!q{ a[0] + a[1] }._v2s;
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*/ =>
txt._s2v.zip(key._s2v.cycle).map!q{ a[0] - a[1] }._v2s;
txt._s2v.zip(key._s2v.cycle).map!q{ a[0] - a[1] }._v2s;