Last active
August 18, 2016 16:30
-
-
Save cedriczirtacic/8923306daa4cf49467ba4561c8206bf4 to your computer and use it in GitHub Desktop.
the cryptopals crypto challenges
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
#!/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