Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- #Input arguments
- our $key = $ARGV[0]; #REDDIT
- our $text = $ARGV[1]; #TODAYISMYBIRTHDAY
- #Possible Values
- our %abc =
- (
- A => 0,
- B => 1,
- C => 2,
- D => 3,
- E => 4,
- F => 5,
- G => 6,
- H => 7,
- I => 8,
- J => 9,
- K => 10,
- L => 11,
- M => 12,
- N => 13,
- O => 14,
- P => 15,
- Q => 16,
- R => 17,
- S => 18,
- T => 19,
- U => 20,
- V => 21,
- W => 22,
- X => 23,
- Y => 24,
- Z => 25
- );
- #Process arguments
- our @text_chars = ();
- our @key_chars = ();
- our @crypted_chars = ();
- #Read arguments
- &process_arguments($key, $text);
- sub process_arguments(){
- #Get Key Length
- @key_chars = split(//, $_[0]);
- my $key_length = scalar @key_chars;
- #Get Text Length
- @text_chars = split(//, $_[1]);
- my $text_length = scalar @text_chars;
- #Extend Key to Text Length
- while($key_length < $text_length){
- push(@key_chars, @key_chars);
- $key_length = scalar @key_chars;
- }
- #Turn hash around
- my %numbers = reverse %abc;
- #Get crypted chars
- my $i = 0;
- for ($i = 0; $i < $text_length; $i++) {
- my $a = $abc{uc($key_chars[$i])};
- my $b = $abc{uc($text_chars[$i])};
- my $sum_mod = ($a+$b)%26;
- $crypted_chars[$i] = $numbers{$sum_mod};
- }
- print @crypted_chars;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement