anonymous Pythonで転置式暗号
Public Domain Python
2021年01月10日
Copy Clone
#ENCRYPTING WITH THE TRANSPOSITION CIPHER

def main():
  myMessage = 'Common sense is not so common.'
  myKey = 8

  print(f'Key : {myKey}\nPlaneText : {myMessage}\nCipherText :{enc_box}')   

def encryptMessage(key, message):

  box=['']
  counter=0
  for i in message:
    box[counter] += i
    if len(box[counter]) == key:
      counter += 1
      box.append('')

  enc_box=''
  for i in range(myKey):
    for k in box:
      if i < len(k):
        enc_box += k[i]

    return enc_box

if __name__ == '__main__':
  main()
#ENCRYPTING WITH THE TRANSPOSITION CIPHER

def main():
  myMessage = 'Common sense is not so common.'
  myKey = 8

  print(f'Key : {myKey}\nPlaneText : {myMessage}\nCipherText :{enc_box}')   

def encryptMessage(key, message):

  box=['']
  counter=0
  for i in message:
    box[counter] += i
    if len(box[counter]) == key:
      counter += 1
      box.append('')

  enc_box=''
  for i in range(myKey):
    for k in box:
      if i < len(k):
        enc_box += k[i]

    return enc_box

if __name__ == '__main__':
  main()
https://ja.wikipedia.org/wiki/%E8%BB%A2%E7%BD%AE%E5%BC%8F%E6%9A%97%E5%8F%B7
をpythonで

ポインターを使うともっとすっきりと書ける。
No one still commented. Please first comment.
Output