Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created May 18, 2018 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save run-dlang/655495013d800d0b75a402e9d13c6fa6 to your computer and use it in GitHub Desktop.
Save run-dlang/655495013d800d0b75a402e9d13c6fa6 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
import std.stdio;
void main()
{
string s = "dhctf{54nc7u5_c4n7_d3c1ph3r_7h15}";
string alph = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz{}";
string res;
auto n = 0;
for(auto i = 0; i < s.length; ++i) {
auto j = 0;
for(; j < alph.length; ++j) if(s[i] == alph[j]) break;
final switch(i % 3) {
case 0:
n += j * 10000;
break;
case 1:
n += j * 100;
break;
case 2:
import std.math: sqrt;
import std.conv: to;
n += j;
while(true) {
//writeln(n);
auto r = cast(int)sqrt(cast(float)n);
n = n - r * r;
if(n == 0) {
res ~= r.to!string ~ ' ';
break;
} else res ~= r.to!string ~ '-';
}
n = 0;
break;
}
}
writeln(res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment