Skip to content

Instantly share code, notes, and snippets.

@yosupo06
Created December 9, 2015 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosupo06/a9dd49b410db979fe7bc to your computer and use it in GitHub Desktop.
Save yosupo06/a9dd49b410db979fe7bc to your computer and use it in GitHub Desktop.
import std.process;
import std.stdio, std.file;
import std.conv;
import std.ascii;
import std.algorithm;
char[] cry(char[] s) {
return execute(["./cryptooo", s]).output.dup;
}
int same(char[] s, char[] t) {
auto n = cast(int)(min(s.length, t.length));
foreach (i; 0..n) {
if (s[i] != t[i]) return i;
}
return n;
}
int main() {
string mp = letters ~ digits ~ "!@#$%^&*()-_=+\\|`~[{]};:'\",<.>/?";
int n = 32;
char[] s = new char[](n);
s[] = 'a';
char[] res = "Encrypted(44): waUqjjDGnYxVyvUOLN8HquEO0J5Dqkh/zr/3KXJCEnw=".dup;
foreach (i; 0..n-1) {
char[] s2;
int ma = -1;
foreach (c; mp) {
foreach (d; mp) {
s[i] = c;
s[i+1] = d;
auto t = cry(s);
int u = same(t, res);
if (ma < u) {
ma = u;
s2 = s.dup;
}
}
}
s = s2.dup;
writeln(s, " ", cry(s));
}
writeln(s);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment