update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
|
|
@ -1,20 +1,21 @@
|
|||
import std.stdio, std.traits;
|
||||
|
||||
pure S rot(S)(in S s, in int key) if (isSomeString!S) {
|
||||
auto res = s.dup;
|
||||
pure S rot(S)(in S s, in int key) pure /*nothrow*/
|
||||
if (isSomeString!S) {
|
||||
auto res = s.dup; // Not nothrow.
|
||||
|
||||
foreach (i, ref c; res) {
|
||||
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 cast(S) res;
|
||||
return res;
|
||||
}
|
||||
|
||||
void main() {
|
||||
int key = 3;
|
||||
auto txt = "The five boxing wizards jump quickly";
|
||||
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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue