From 868e3403ee4bb92cbbbbdfdb3b06b58da114a949 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 14 Jan 2014 16:13:58 +0100 Subject: [PATCH] Administration: can edit exercices --- check.pl | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/check.pl b/check.pl index 147e5ca0..a45d8077 100755 --- a/check.pl +++ b/check.pl @@ -5,6 +5,8 @@ use strict; use warnings; use DBI; use File::Basename; +use Digest::MD5 qw(md5_hex); +use Digest::SHA qw(sha1_hex sha224_hex sha256_hex sha384_hex sha512_hex); #Return number of good solutions my $exit = 0; @@ -75,13 +77,35 @@ for my $f (readdir $dh) my $type = @$row[0]; my $sol = @$row[1]; - if ($type eq "raw" && $sol ne $solution) { - $good = 0; - last; + my $tmp_solution = $solution; + + if ($type eq "md5") { + $tmp_solution = md5_hex($solution); + } + elsif ($type eq "sha1") { + $tmp_solution = sha1_hex($solution); + } + elsif ($type eq "sha224") { + $tmp_solution = sha224_hex($solution); + } + elsif ($type eq "sha256") { + $tmp_solution = sha256_hex($solution); + } + elsif ($type eq "sha384") { + $tmp_solution = sha384_hex($solution); + } + elsif ($type eq "sha512") { + $tmp_solution = sha512_hex($solution); } elsif ($type ne "raw") { - $good = 0; warn "$type not implemented"; + } + + say STDERR "check: $sol vs $tmp_solution"; + + if ($sol ne $tmp_solution) + { + $good = 0; last; } }