I would like to translate (Encrypte) a code from a variable.
This code is made of 3 numbers and substitution must respect a rule according number position.
For exemple:
If number 1 is the first position in the code, it must be translated to A
If number 1 is the second position in the code, it must be translated to B
If number 1 is the third position in the code, it must be translated to C
If number 0 is the first position in the code, it must be translated to Z
If number 0 is the second position in the code, it must be translated to Y
If number 0 is the third position in the code, it must be translated to X
If number 2 is the first position in the code, it must be translated to M
If number 2 is the second position in the code, it must be translated to N
If number 2 is the third position in the code, it must be translated to P
If the code is 102, translated code will be AYP
I have written following code but it doesn't run.
Expand|Select|Wrap|Line Numbers
- my $EncodedLockJob=0;
- my LockJob0="AZM";
- my LockJob1="BYN";
- my LockJob2="CXP";
- my $LockJobLength=3;
- my LockJobCharIndex;
- my LockJobChar;
- my LockJobN;
- for ($LockJobCharIndex = 0; $LockJobCharIndex < $LockJobLength; $i++) {
- $LockJobChar = substr(102, LockJobCharIndex, 1);
- if ($LockJobChar == "0")
- { $LockJobN = $LockJob0; }
- elsif ($LockJobChar == "1")
- { $LockJobN = $LockJob1; }
- else ($LockJobChar == "2")
- { $LockJobN = $LockJob2; }
- $EncodedLockJob = $EncodedLockJob + substr($LockJobN, $LockJobCharIndex, 1);
Thanks for your help