Created
January 21, 2015 09:45
-
-
Save UplinkCoder/f2f498259a2ae150d563 to your computer and use it in GitHub Desktop.
rot13-leetify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module rot13_leetify; | |
import std.stdio; | |
import std.algorithm:map,filter; | |
char rot13(char c) pure { | |
switch(c) { | |
case 'a': .. case 'm': | |
case 'A' : .. case 'M': | |
c+=13; | |
break; | |
case 'n' : .. case 'z' : | |
case 'N' : .. case 'Z' : | |
c-=13; | |
break; | |
default : break; | |
} | |
return c; | |
} | |
char leetify(char c) { | |
struct LeetStruct { | |
uint number; | |
char chr; | |
} | |
static immutable LeetStruct[] leetArray = [{4,'a'}, {7,'t'}, {1,'l'}, {3,'e'}, {0,'o'}]; | |
import std.conv; | |
import std.array; | |
import std.ascii; | |
auto filterResult = leetArray. | |
filter!(e => e.chr == c.toLower). | |
map!(e => to!string(e.number)).array; | |
return filterResult ? filterResult[0][0] : c; | |
} | |
char rot13(dchar c) pure { | |
return rot13(cast(char)c); | |
} | |
void main(string[] args) | |
{ | |
import std.array; | |
writeln("TDPL".map!(c => leetify(cast(char) c))); | |
writeln(map!rot13("Uryyb Jbeyq!") | |
.filter!(l => l !='H') | |
.map!(l => leetify(cast(char)l))); | |
// Lets the user press <Return> before program returns | |
stdin.readln(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment