Created
May 18, 2018 16:31
-
-
Save run-dlang/655495013d800d0b75a402e9d13c6fa6 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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
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