1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Smalltalk で単アルファベット換字式暗号を作る

Last updated at Posted at 2019-09-28

 暗号解読の作問をするためのプログラムを Smalltalk(Squeak 6.0) で書いてみました。ソースコードは以下の通りです。

|plainText cryptoKey stream|

plainText := 'This is plain text.' asLowercase.

cryptoKey := Character alphabet shuffle.

Transcript cr; show: 'Key is: ' , cryptoKey; cr.

stream := TextStream with: ''.
plainText do: [:each ||index|
	index := Character alphabet indexOf: each.
	index = 0 ifTrue: [
		stream nextPut: each.		
		]
	ifFalse: [
		stream nextPut: (cryptoKey at: index).		
	]
].

Transcript cr; show: stream contents.

 結果、こんな問題が出来ました。
https://gist.github.com/satoyuichi/f27b3b9b9911da69c7dce5977f27c2d1

解説

 暗号は単アルファベット換字式暗号です。アルファベットをスクランブルしたものを鍵として、平文を暗号化しています。平文をすべて小文字に変換しているのは解読しやすくするためです。記号やスペースをそのままにしているのも解読しやすくするためですが、同様にスクランブルするのであれば、

cryptoKey := Character alphabet shuffle.

cryptoKey := (Character alphabet , '.,:; ') shuffle.

などのようにすれば対応できます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?