This is the encryption challenge. The decryption challenge can be found here.
The challenge is to encrypt a given string, using the rules as specified below. The string will only contain lowercase alphabets, digits, and/or blank spaces.
Equivalent of a Character
Now, firstly you would need to know how to find the "equivalent" of each character.
If the character is a consonant, this is the way of finding it's equivalent:
1) List all the consonants in alphabetical order b c d f g h j k l m n p q r s t v w x y z 2) Get the position of the consonant you are finding the equivalent of. 3) The equivalent is the consonant at that position when starting from the end.
eg: 'h' and 't' are equivalents of each other because 'h', 't' are in the 6th position from start and end respectively.
The same procedure is followed to find the equivalent of vowels/digits. You list all the vowels or the digits (starting from 0) in order and find the equivalent.
Given below is the list of the equivalents of all the characters:
b <-> z c <-> y d <-> x f <-> w g <-> v h <-> t j <-> s k <-> r l <-> q m <-> p n <-> n a <-> u e <-> o i <-> i 0 <-> 9 1 <-> 8 2 <-> 7 3 <-> 6 4 <-> 5
Rules of Encrypting
You start moving from the left and go towards the right.
If the character is a consonant/digit, then its equivalent is taken and if it is a blank space, then a blank space is taken.
If the character is a vowel, you take it's equivalent and start to move in the opposite direction. For example, if you are moving right and encounter a vowel, encrypt that character then skip to the rightmost unencrypted character and begin encrypting in the left direction, and vice versa.
You shouldn't consider a character in the same position twice. The steps should be followed until all the characters in the input are covered.
The total number of characters in the input(including blank spaces) should be equal to the total number of characters in the output.
Please note that the encrypted characters appear in the output in the order in which they were encrypted.
Now let me encrypt a string for you.
String = "tre d1go3t is" Moving left to right "t" -> "h" "r" -> "k" "e" -> "o" Vowel encountered. Now moving right to left. "s" -> "j" "i" -> "i" Vowel encountered. Now moving left to right. " " -> " " "d" -> "x" "1" -> "8" "g" -> "v" "o" -> "e" Vowel encountered. Now moving right to left. " " -> " " "t" -> "h" "3" -> "6" Output -> "hkoji x8ve h6"
"flyspy" -> "wqcjmc" "hero" -> "toek" "heroic" -> "toyike" "ae" -> "uo" "abe" -> "uoz" "the space" -> "htoo jmuy" "a d1g13t" -> "uh68v8x " "we xi12" -> "fo78i d" "this is a code" -> "htioj ixej uy "
You may also choose to use uppercase alphabets instead of lowercase.
This is code-golf, so the shortest code wins!