-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExerciseCoding.pl
More file actions
executable file
·69 lines (57 loc) · 1.38 KB
/
ExerciseCoding.pl
File metadata and controls
executable file
·69 lines (57 loc) · 1.38 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl
use strict;
use warnings;
use Sys::Virt;
use Crypt::Tea;
use Crypt::Random;
use String::Random;
use lib '/scripts/common_perl/';
use Framework qw(&cryptText &decryptText);
my %DMin=();
my %DMax=();
$DMin{1}=1;
$DMax{1}=2;
$DMin{2}=301;
$DMax{2}=600;
$DMin{3}=601;
$DMax{3}=800;
$DMin{4}=801;
$DMax{4}=900;
$DMin{5}=901;
$DMax{5}=1000;
# Difficulty 0 = TEST Mode
if (((scalar @ARGV) < 2) && (($ARGV[1] ne "1") || ($ARGV[1] ne "1") || ($ARGV[1] ne "2") || ($ARGV[1] ne "3") || ($ARGV[1] ne "4") || ($ARGV[1] ne "5")) )
{
print "\n\nUsing of the script:\n";
print "1. argument: Path of your file, that contains the username (1 in each line)\n";
print "2. argument: Exercise difficulty, must be between 0 and 5 (0=TEST MODE)";
print "\t E.g ./ExerciseCoding '/tmp/usersfile.txt' '1'\n\n";
die;
}
my $UserFile=$ARGV[0];
my $Difficulty=$ARGV[1];
my $fn;
open ($fn,"<","$UserFile") or die "Can't read $UserFile!!";
print "Username;Password;Exercise\n";
while (my $U = <$fn>)
{
chomp($U);
my $pass = new String::Random;
my $password = $pass->randpattern("CnCcnC");
my $e=-1;
if ($Difficulty == 0)
{#if TEST MDOE
$e = "TEST";
}
else
{# If EXAM
while (!(($e>=$DMin{$Difficulty})&&($e<=$DMax{$Difficulty})))
{
$e = int(rand($DMax{$Difficulty}));
}
}
my $exercise=cryptText("$e","${U}${pass}");
# print "EXERCISE=$e\n";
print "$U;$password;$exercise\n";
}
close($fn);