# Note

This is the decryption challenge. The encryption challenge can be found here.

# Challenge

The challenge is to decrypt a given string, using the rules as specified below. The string will only contain lowercase alphabets, digits, and/or blank spaces. If you want to know how the input string has been encrypted, refer to this challenge!

# 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 Decrypting

1. You start with two empty strings, let's call them s1 and s2. We will be moving from left to right of the input string. At the beginning, we would be considering the first empty string, i.e, s1. We will be switching between the two strings whenever we encounter a vowel.

2. We take the equivalent of the current character of the input string, or a blank space if it is a blank space. Let's call this character c. c is now appended to the right of s1 (if we are considering s1 currently) or to the left of s2 (if we are considering s2 currently).

3. If that character was a vowel, switch to the other string now (s1 <-> s2).

4. Repeat step 2 (and 3 for vowels) for every character in the input string.

5. Concatenate s1 and s2 and the result is the decrypted string.

Now let me decrypt a string for you.

String = "htioj ixej uy "
Initially, s1 = s2 = ""
Current: s1
Moving left to right
"h" -> "t" (s1 = "t")
"t" -> "h" (s1 = "th")
"i" -> "i" (s1 = "thi")
Vowel encountered. Switching to s2 now.
"o" -> "e" (s2 = "e")
Vowel encountered. Switching to s1 now.
"j" -> "s" (s1 = "this")
" " -> " " (s1 = "this ")
"i" -> "i" (s1 = "this i")
Vowel encountered. Switching to s2 now.
"x" -> "d" (s2 = "de") [Note that when dealing with s2, we append to the left]
"e" -> "o" (s2 = "ode")
Vowel encountered. Switching to s1 now.
"j" -> "s" (s1 = "this is"
" " -> " " (s1 = "this is ")
"u" -> "a" (s1 = "this is a")
Vowel encountered. Switching to s2 now.
"y" -> "c" (s2 = "code")
" " -> " " (s2 = " code")
Now, append s1 and s2 to get:
"this is a code"

Output -> "this is a code"


# Examples

"wqcjmc" -> "flyspy"
"toek" -> "hero"
"toyike" -> "heroic"
"uo" -> "ae"
"uoz" -> "abe"
"htoo jmuy" -> "the space"
"uh68v8x " -> "a d1g13t"
"fo78i d" -> "we xi12"
"htioj ixej uy " -> "this is a code"
"jea ceeac hnx8x vni kokhj jiuth xoqqc xohmcky" -> "so you really decrypted this string d1dnt you"


You may also choose to use uppercase alphabets instead of lowercase.

# Scoring

This is , so the shortest code wins!

# Jelly, 29 bytes

ØḄ,ØẹØDṭ,U$F€yµe€ØẹŻœṗµ;ṚU$m2


A full program which prints the decoded text.

Try it online!

### How?

ØḄ,ØẹØDṭ,U$F€yµe€ØẹŻœṗµ;ṚU$m2 - Main Link: list, S
ØḄ                            - consonant characters
Øẹ                         - vowel characters
,                           - pair
ØD                       - digit characters
ṭ                      - tack -> ["bcd...","aeiou","012..."]
$- last two links as a monad: U - upend -> ["...dcb","uoiea","...210"] , - pair -> [["bcd...","aeiou","012..."],["...dcb","uoiea","...210"]] F€ - flatten each -> ["bcd...aeiou012...","...dcbuoiea...210"] y - translate S using that map µ - new monadic chain (i.e. f(A=that)) Øẹ - vowel characters e€ - (for c in A) exists in (vowels)? Ż - prepend a zero œṗ - partition (A) before truthy elements (of that) µ - new monadic chain (i.e. f(that)) ...e.g.: f(["thi","e","s i","do","s a","c "])$   - last two links as a monad:
Ṛ     -   reverse    ["c ","s a","do","s i","e","thi"]
U    -   upend      [" c","a s","od","i s","e","iht"]
;      - concatenate  ["thi","e","s i","do","s a","c "," c","a s","od","i s","e","iht"]
m2 - mod-2 slice  ["thi",    "s i",     "s a",    ," c",      "od",      "e"      ]
- implicit, smashing print -> this is a code


# JavaScript (ES6),  112 110  109 bytes

Expects an array of characters.

s=>s.map(c=>(C="bzcydxfwgvhtjskrlqmpnn  aueoii",c=C[j=C.search(c)^1]||9-c,+s?b=c+b:a+=c,s^=j>23),a=b='')&&a+b


Try it online!

### How?

We look for the index of each character c in the following lookup string:

 0         1         2
012345678901234567890123456789
"bzcydxfwgvhtjskrlqmpnn  aueoii"


If the character is not found, it must be a digit which is replaced with 9-c. Otherwise, we get the position of the counterpart character by inverting the least significant bit of the index.

For instance: j1213s

The new character is either appended to a or prepended to b.

We switch between a and b whenever the index is greater than 23 -- i.e. c is a vowel.

# Python, 226, 160 146 bytes

Try it Online

I am fairly new to python and wanted to try this challenge. I know a lot of this can be improved using lambda or simplified code. I am showing my code so I can get feedback.

Thanks to @Arnauld for helping me learn new ways to code. Now at 160 bytes

More inputs and refinements. Now at 146.

def k(y):
x='aueoiibzcydxfwgvhtjskrlqmpnn0918273645  '
s=1
b=['']*2
for i in y:n=x.find(i);b[s]+=x[n+1-2*(n%2)];s^=n<6
print(b[1]+b[0][::-1])


Old Code:

def k(y):
x='aueoiibzcydxfwgvhtjskrlqmpnn0918273645  '
s=1
b=c=''
def a(t):
m=n+1 if n%2==0 else n-1;t+=x[m];return t
for i in y:
n=x.find(i)
if s:
b=a(b)
else:
c=a(c)
if n<=5:s=not s
b+=c[::-1]
print(b)

k('wqcjmc')
k('toek')
k('toyike')
k('uo')
k('uoz')
k('htoo jmuy')
k('uh68v8x ')
k('fo78i d')
k('htioj ixej uy ')
k('jea ceeac hnx8x vni kokhj jiuth xoqqc xohmcky')


Tested all the sample items and got the correct response.

"wqcjmc" -> "flyspy"
"toek" -> "hero"
"toyike" -> "heroic"
"uo" -> "ae"
"uoz" -> "abe"
"htoo jmuy" -> "the space"
"uh68v8x " -> "a d1g13t"
"fo78i d" -> "we xi12"
"htioj ixej uy " -> "this is a code"
"jea ceeac hnx8x vni kokhj jiuth xoqqc xohmcky" -> "so you really decrypted this string d1dnt you"

• Nice 1st answer, please post a tio.run link to your code that doesn't contain any comments. Commented Aug 22, 2020 at 10:01
• Welcome to the site. You might find Tips for golfing in Python useful. Commented Aug 22, 2020 at 12:05
• Some tips: Use n<6 instead of n<=5. Use s=1-s instead of s=not s. You can replace def a(t):... with a=lambda t:t+x[n+1-2*(n%2)] (197 bytes). Commented Aug 22, 2020 at 13:28
• Going a step further, you can save many bytes by using a list of strings instead of b and c (160 bytes) Commented Aug 22, 2020 at 13:36
• This is why I love this community. Learning things everyday. Thank You for the tips @Arnauld and Dingus Commented Aug 22, 2020 at 15:02

# Retina 0.8.2, 898380 71 bytes

[aeiou]|&¶
+(¶.+)¶(.*)2$1 O$^r.\G

T¶b-df-hj-maed\oup-tv-z_Ro


Try it online! Link includes test cases. This turned out to be easier than encoding, as demonstrated by the fact that I was able to code it in Retina 0.8.2 rather than requiring Retina 1. Explanation:

[aeiou]|&¶


Split the input on substrings ending on vowels. An extra split is forced at the end of the string so that there are at least two lines.

+(¶.+)¶(.*)2$1  Join alternate lines together, so that the first line is the concatenation of all the odd lines and the second line is the concatenation of all the even lines. r.\G  Matching only the characters on the last (second) line... O$^



.. reverse the matches, thus reversing the second line only.

T¶b-df-hj-maed\oup-tv-z_Ro


Join the two lines together and decode the letters. The Ro causes the string to transliterate to its reverse. The middle consonant n and vowel i map to themselves so don't need to be listed. The ¶ maps to the special _ thus deleting it. The first and last 10 consonants and the first and last two vowels then surround the digits. (The o is normally special so it has to be quoted here.)

# R, 190 bytes

function(i,/=strsplit){a=el(" 01234aeibcdfghjklmnpqrstvwxyziou98765 "/"")
names(a)=rev(a)
j=k=""
for(l in a[el(i/"")]){if(T)j=c(j,l)else k=c(l,k)
if(grepl(l,"aeiou"))T=!T}
cat(j,k,sep="")}


Try it online!

Note to self: learn a new, non-R, language to golf text-based challenges...

Commented:

decrypt=function(i,
/=strsplit){                  # use infix '/' as alias to strsplit function
a=el(" 01234aeibcdfghjklmnpqrstvwxyziou98765 "/"")
# a=vector of characters with equivalents at reverse index
names(a)=rev(a)                # name characters by equivalent
j=k=""                         # initialize j,k as empty strings
for(l in a[el(i/"")]){         # for each input letter (split using /), find its equivalent l
if(T)j=c(j,l)else k=c(l,k)    #  if T=1 (initial value) append l to j, otherwise put it at start of k
if(grepl(l,"aeiou"))T=!T}     #  if it was a vowel, T=not T
cat(j,k,sep="")}               # finally, output j,k


# C (gcc), 144143 140 bytes

-1 -3 bytes thanks to ceilingcat

k,v,p,a;f(char*s,char*o){for(k=p=0,v=strlen(s);a=*s++;p^=1065233>>a-97&1)o[p?--v:k++]=a<33?a:a<58?105-a:"uzyxowvtisrqpnemlkjhagfdcb"[a-97];}


Try it online!

# 05AB1E, 27 26 bytes

žMIå0šÅ¡ι€SR«žNÂ‡žMÂ‡žhÂ‡


I/O as a list of characters.

Try it online or verify all test cases (with the I/O joined to pretty-print).

Explanation:

žM             # Push the vowels "aeiou"
Iå           # Check for each character in the input-list if it's in the vowel string
#  i.e. ["h","t","i","o","j"," ","i","x","e","j"," ","u","y"," "]
#   → [0,0,1,1,0,0,0,1,0]
0š         # Prepend a leading 0
#  → [0,0,0,1,1,0,0,0,1,0]
Å¡       # Split the (implicit) input-string on the truthy values
#  → [["h","t","i"],["o"],["j"," ","i"],["x","e"],["j"," ","u"],["y"," "]]
ι      # Uninterleave the list of lists
#  → [[["h","t","i"],["j"," ","i"],["j"," ","u"]],[["o"],["x","e"],["y"," "]]]
€S    # Convert each inner list of lists to a flattened list of characters
#  → [["h","t","i","j"," ","i","j"," ","u"],["o","x","e","y"," "]]
   # Push both lists of characters separated to the stack
#  → ["h","t","i","j"," ","i","j"," ","u"] and ["o","x","e","y"," "]
R  # Reverse the second string
#  → ["h","t","i","j"," ","i","j"," ","u"] and [" ","y","e","x","o"]
« # Merge the two lists together
#  → ["h","t","i","j"," ","i","j"," ","u"," ","y","e","x","o"]
žN             # Push the consonants "bcdfghjklmnpqrstvwxyz"
Â            # Bifurcate it; short for Duplicate & Reverse copy
‡           # Transliterate the "bcdfghjklmnpqrstvwxyz" to "zyxwvtsrqpnmlkjhgfdcb"
#  → ["t","h","i","s"," ","i","s"," ","u"," ","c","e","d","o"]
žMÂ‡           # Do the same for the vowels "aeiou"
#  → ["t","h","i","s"," ","i","s"," ","a"," ","c","o","d","e"]
žhÂ‡           # And the digits "0123456789"
#  → ["t","h","i","s"," ","i","s"," ","a"," ","c","o","d","e"]
# (after which the result is output implicitly)


# Perl 5-F, 110 bytes

map{push@{$o[$i]},y/0-9a-z/9876543210uzyxowvtisrqpnemlkjhagfdcb/r;$i^=/[aeiou]/}@F;say@{$o[0]},reverse@{\$o[1]}
`

Try it online!