-
Notifications
You must be signed in to change notification settings - Fork 0
/
chal15.pl
executable file
·55 lines (49 loc) · 1.04 KB
/
chal15.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl -w
# chal15.pl - PKCS#7 padding validation
#
# Copyright (C) 2015 Andrew J. Zimolzak <andyzimolzak@gmail.com>
# Full notice is found in the file 'LICENSE' in the same directory
# as this file.
use strict;
use Cryptopals qw(strip_valid_padding);
use Try::Tiny;
try {
print strip_valid_padding("ICE ICE BABY\x04\x04\x04\x04"), "\n";
}
catch {
if (/Bad padding/) {
chomp;
die "Error in GOOD string?! ($_)$!";
}
else {
chomp;
die "unknown error $_ $!";
}
};
try {
print strip_valid_padding("ICE ICE BABY\x05\x05\x05\x05"), "\n";
die "Bad string 1 failed to throw exception$!";
}
catch {
if (/Bad padding/) {
print "Caught, as predicted.\n";
}
else {
chomp;
die "unknown error ($_)$!";
}
};
try {
print strip_valid_padding("ICE ICE BABY\x01\x02\x03\x04"), "\n";
die "Bad string 2 failed to throw exception$!";
}
catch {
if (/Bad padding/) {
print "Caught, as predicted.\n";
}
else {
chomp;
die "unknown error ($_)$!";
}
};
warn "Passed assertions ($0)\n";