มาถอดรหัสกัน!
บันทึก
นี่คือความท้าทายในการถอดรหัส ความท้าทายในการเข้ารหัสสามารถพบได้ที่นี่
ท้าทาย
ความท้าทายคือการถอดรหัสสตริงที่กำหนดโดยใช้กฎตามที่ระบุด้านล่าง สตริงจะมีตัวพิมพ์เล็กตัวอักษร , ตัวเลขและ / หรือช่องว่าง หากคุณต้องการทราบว่าสตริงอินพุตถูกเข้ารหัสอย่างไรโปรดอ้างถึงความท้าทายนี้!
เทียบเท่ากับตัวละคร
ตอนนี้อันดับแรกคุณจะต้องรู้วิธีหา "เทียบเท่า" ของอักขระแต่ละตัว
หากอักขระเป็นพยัญชนะนี่คือวิธีการหาค่าที่เทียบเท่า:
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.
เช่น: 'h' และ 't' มีค่าเท่ากันเนื่องจาก 'h', 't' อยู่ในตำแหน่งที่ 6 ตั้งแต่เริ่มต้นและสิ้นสุดตามลำดับ
ตามขั้นตอนเดียวกันนี้เพื่อค้นหาความเทียบเท่าของสระ / หลัก คุณแสดงรายการเสียงสระหรือตัวเลขทั้งหมด (เริ่มจาก 0) ตามลำดับและหาค่าที่เทียบเท่า
ด้านล่างนี้คือรายชื่อตัวละครที่เทียบเท่ากันทั้งหมด:
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
กฎของการถอดรหัส
คุณเริ่มต้นด้วยสองสายที่ว่างเปล่าขอเรียกพวกเขาและ
s1s2เราจะย้ายจากซ้ายไปขวาของสตริงอินพุต ในตอนต้นเราจะพิจารณาสตริงว่างแรกคือs1. เราจะสลับไปมาระหว่างสองสายเมื่อใดก็ตามที่เราพบกับเสียงสระเราใช้อักขระปัจจุบันที่เทียบเท่าของสตริงอินพุตหรือช่องว่างถ้าเป็นช่องว่าง ขอเรียกตัวละคร
cนี้cตอนนี้ต่อท้ายทางด้านขวาของs1(หากเรากำลังพิจารณาs1อยู่) หรือทางด้านซ้ายของs2(หากเรากำลังพิจารณาs2อยู่)ถ้าอักขระนั้นเป็นเสียงสระให้เปลี่ยนไปใช้สตริงอื่นทันที (
s1 <-> s2)ทำซ้ำขั้นตอนที่ 2 (และ 3 สำหรับเสียงสระ) สำหรับทุกอักขระในสตริงอินพุต
เชื่อมต่อ
s1และs2ผลลัพธ์คือสตริงที่ถอดรหัส
ตอนนี้ให้ฉันถอดรหัสสตริงให้คุณ
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"
ตัวอย่าง
"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"
คุณยังสามารถเลือกใช้ตัวพิมพ์ใหญ่แทนตัวพิมพ์เล็กได้
การให้คะแนน
นี่คือรหัสกอล์ฟดังนั้นรหัสที่สั้นที่สุดจึงชนะ!
คำตอบ
เยลลี่ 29 ไบต์
ØḄ,ØẹØDṭ,U$F€yµe€ØẹŻœṗµ;ṚU$m2
โปรแกรมเต็มรูปแบบที่พิมพ์ข้อความที่ถอดรหัส
อย่างไร?
ØḄ,ØẹØ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 110109 ไบต์
คาดหวังอาร์เรย์ของอักขระ
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
อย่างไร?
เรามองหาดัชนีของแต่ละอักขระcในสตริงการค้นหาต่อไปนี้:
0 1 2
012345678901234567890123456789
"bzcydxfwgvhtjskrlqmpnn aueoii"
9-cถ้าตัวละครไม่พบมันจะต้องเป็นหลักซึ่งจะถูกแทนที่ด้วย มิฉะนั้นเราจะได้ตำแหน่งของอักขระคู่กันโดยการพลิกกลับบิตที่มีนัยสำคัญน้อยที่สุดของดัชนี
ยกตัวอย่างเช่น: j→การ12→การ13→การs
ตัวละครใหม่จะถูกผนวกทั้งหรือใช้ได้กับab
เราสลับไปมาaและbเมื่อใดก็ตามที่ดัชนีมีค่ามากกว่า 23 - นั่นcคือเสียงสระ
Python, 226, 160 146 ไบต์
ฉันค่อนข้างใหม่สำหรับ python และอยากลองความท้าทายนี้ ฉันรู้ว่าหลายอย่างสามารถปรับปรุงได้โดยใช้ lambda หรือโค้ดแบบง่าย ฉันกำลังแสดงรหัสของฉันเพื่อรับความคิดเห็น
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"
Retina 0.8.2, 89 83 80 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="")}
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), 144 143 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];}
05AB1E, 27 26 bytes
žMIå0šÅ¡ι€S`R«ž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]}