Skip to content

Instantly share code, notes, and snippets.

@cedriczirtacic
Last active August 18, 2016 16:30
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 cedriczirtacic/8923306daa4cf49467ba4561c8206bf4 to your computer and use it in GitHub Desktop.
Save cedriczirtacic/8923306daa4cf49467ba4561c8206bf4 to your computer and use it in GitHub Desktop.
the cryptopals crypto challenges
#!/bin/env perl
while(<>){
chomp;
$uhex = pack('H*', $_);
$udec = pack('u', $uhex );
$udec =~s/(^.|[\n\r])//mg;
$udec =~tr#` -_#AA-Za-z0-9+/#;
print $udec, $/;
}
exit 0
#!/bin/env perl
$_ = <> and chomp;
$msg = pack('H*', $_);
$_ = <> and chomp;
$xor = pack('H*', $_);
$i = 0;
$xored = undef;
while( $i <= length($msg) ){
$xored.= substr($msg, $i, 1) ^ substr($xor, $i, 1);
$i++;
}
print unpack('H*', $xored),$/;
exit 0
#!/bin/env perl
%chars = ();
$_ = <> and chomp;
@msg = split //, pack('H*', $_);
foreach $l(@msg){
$chars{$l} = 1 and next if(! exists($chars{$l}) );
$chars{$l}++;
}
foreach( sort {$chars{$b} <=> $chars{$a} } keys(%chars) ){
print $_,": ";
foreach $l( @msg){
print chr(ord($l)^ord($_));
}
print $/;
}
exit 0
#!/bin/env perl
$_ = <> and chomp;
@msg = split //, pack('H*', $_);
@char_table = qw( E T A O I N S R H D L U C M F Y W G P B V K X Q J Z );
foreach $c(@char_table){
print $c,": ";
foreach $l( @msg){
print chr(ord($l)^ord($c));
}
print $/;
$l_c = lc($c);
print $l_c,": ";
foreach $l( @msg){
print chr(ord($l)^ord($l_c));
}
print $/;
}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment