解読しよう!

Aug 22 2020

注意

これは復号化の課題です。暗号化の課題はここにあります。

チャレンジ

課題は、以下に指定されているルールを使用して、特定の文字列を復号化することです。文字列には、小文字のアルファベット数字空白スペースのみが含まれます。入力文字列がどのように暗号化されているかを知りたい場合は、このチャレンジを参照してください。

キャラクターに相当

ここで、最初に、各文字の「同等」を見つける方法を知る必要があります。

文字が子音である場合、これは同等のものを見つける方法です。

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」はそれぞれ開始と終了から6番目の位置にあるため、「h」と「t」は互いに同等です。

同じ手順に従って、母音/数字に相当するものを見つけます。すべての母音または数字(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

復号化のルール

  1. 2つの空の文字列から始めて、それらをs1とと呼びましょうs2。入力文字列の左から右に移動します。最初に、最初の空の文字列、つまりs1。を検討します。母音に遭遇するたびに、2つの文字列を切り替えます。

  2. 入力文字列の現在の文字に相当するもの、または空白の場合は空白を使用します。このキャラクターを呼びましょうcc現在 s1s1現在検討している場合)の右側または(現在検討している場合)の左側に 追加されます。s2s2

  3. その文字が母音だった場合は、今すぐ他の文字列に切り替えてください(s1 <-> s2)。

  4. 入力文字列のすべての文字について、手順2(および母音の場合は3)を繰り返します。

  5. 連結するs1s2、結果は復号化された文字列になります。

次に、文字列を復号化します。

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"

小文字の代わりに大文字のアルファベットを使用することもできます。

スコアリング

これはコードゴルフなので、最短のコードが勝ちます!

回答

5 JonathanAllan Aug 22 2020 at 02:48

ゼリー、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
4 Arnauld Aug 22 2020 at 03:06

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。に置き換えられた数字である必要があります。それ以外の場合は、インデックスの最下位ビットを反転することにより、対応する文字の位置を取得します。

例えば:j1213s

新しい文字は、に追加aまたは先頭に追加されbます。

インデックスが23より大きい場合、つまり母音である場合はいつでも、aとを切り替えます。bc

4 JoeFerndz Aug 22 2020 at 16:44

Python、226、160146バイト

オンラインでお試しください

私はPythonにかなり慣れていないので、このチャレンジを試してみたかったのです。私はこれの多くがラムダまたは簡体字コードを使用して改善できることを知っています。フィードバックを受け取ることができるように、コードを表示しています。

新しいコーディング方法を学ぶのを手伝ってくれた@Arnauldに感謝します。今160バイトで

より多くの入力と改良。今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])

古いコード:

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')

すべてのサンプルアイテムをテストし、正しい応答を得ました。

"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"
2 Neil Aug 22 2020 at 06:50

網膜0.8.2、89の 83 80 71バイト

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

T`¶b-df-hj-maed\oup-tv-z_`Ro

オンラインでお試しください!リンクにはテストケースが含まれています。これは、Retina1を必要とせずにRetina0.8.2でコーディングできたという事実によって示されるように、エンコードよりも簡単であることがわかりました。説明:

[aeiou]|$ $

母音で終わる部分文字列で入力を分割します。少なくとも2行になるように、文字列の最後に追加の分割が強制されます。

+`(¶.+)¶(.*)$ $2$1

最初の行がすべての奇数行の連結であり、2番目の行がすべての偶数行の連結であるように、代替行を結合します。

r`.\G

最後の(2番目の)行の文字のみを照合します。

O$^`

..一致を逆にして、2行目だけを逆にします。

T`¶b-df-hj-maed\oup-tv-z_`Ro

2つの行を結合し、文字をデコードします。これRoにより、文字列が逆に音訳されます。中央の子音nと母音iはそれ自体にマッピングされるため、リストする必要はありません。特別にマップ_を削除するように。次に、最初と最後の10個の子音と、最初と最後の2つの母音が数字を囲みます。(o通常は特別なので、ここで引用する必要があります。)

2 DominicvanEssen Aug 27 2020 at 01:51

R、190バイト

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="")}

オンラインでお試しください!

自己への注意:ゴルフのテキストベースの課題に対する新しい非R言語を学ぶ...

コメント:

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
2 gastropner Aug 22 2020 at 08:26

C(gcc)、144 143140バイト

-ceilingcatのおかげで1〜3バイト

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];}

オンラインでお試しください!

KevinCruijssen Aug 24 2020 at 13:59

05AB1E、27の26バイト

žMIå0šÅ¡ι€S`R«žN‡žM‡žh‡

文字のリストとしてのI / O。

オンラインそれを試してみたり、すべてのテストケースを検証する(I / Oはかなり-プリントに参加して)。

説明:

ž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)
Xcali Sep 04 2020 at 05:45

Perl 5、110 -Fバイト

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

オンラインでお試しください!