We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
fromstringimportascii_uppercaseasaaadefdecode(k,m):# Removes duplicates from keykey=''.join([xfori,xinenumerate(k)ifk.index(x)==i])# Get aplhabet without chars in keyalph=''.join([xforxinaaaifxnotinkey])# Get base ordered chardec=key+alph# Creates columns by indexing: range() with steps of len(key) and# Increases the start-value from 0 to len(key) + sorts themcolumns=sorted([''.join([dec[x]forxinrange(n,len(dec),len(key))])forninrange(len(key))])# Creates a decoding dictd={a:bforb,ainzip(aaa,''.join(columns))}# Decodereturn''.join(d[x]ifxindelse' 'forxinm)for_inrange(int(input())):key=input()mes=input()print(decode(key,mes))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Keyword Transposition Cipher
You are viewing a single comment's thread. Return to all comments →
Python 3