Nikos said:
#!/usr/bin/perl
print "Enter text to be encrypted: ";
$toBeEncrypted = <>;
@letters = split //, $toBeEncrypted; # load the user input to an array
letter by letter
foreach (@letters) {
$letters[$_] = chr($letters[$_] + 1); # take each letter and convert it
to the next one alphabetically
}
print "Encrypted text now is: @letters\n";
I have made the ebove, but somehow aint working.
$_ is an alias for the currently selected element of @letters. Also, if
$_ contains a letter, it contains a letter, not a number, so
incrementing won't work:
$_ = chr(ord($_) + 1);
If you've added "use warnings; use strict;", perl would've told you that
Enter text to be encrypted: Hello
Argument "H" isn't numeric in array element at enc.pl line 12, <> line 1.
Argument "e" isn't numeric in array element at enc.pl line 12, <> line 1.
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.
Argument "l" isn't numeric in array element at enc.pl line 12, <> line 1.
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.
Argument "l" isn't numeric in array element at enc.pl line 12, <> line 1.
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.
Argument "o" isn't numeric in array element at enc.pl line 12, <> line 1.
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.
Argument "\n" isn't numeric in array element at enc.pl line 12, <> line 1.
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.
Encrypted text now is: e l l o
Note: You should watch out for wrap-arounds ("encrypting" the last
letter in the alphabet).
Josef