SYSTEM NOTICE

Auto translation by AI. Be sure, accuracy, nuances and authorial intent may not be fully reflected.
芋出し画像

Just copy and paste! A simple 'Modern Enigma'

The like limit is tough...😭


Just keep it in your bookmarks!

A simple tool you can just copy and paste!

Easy with Gemini! Create a tool!

Introducing a prompt to create it in one go!


Is there anything that comes to mind when you hear the word 'cipher'?
The 'Enigma' used by Germany during World War II.
I knew the word, but I didn't know what it actually was.
When I asked Gemini if it could make one, it said, 'I can.'
So, I wanted it to try making one!


Since we're at it, let's change things up and have Gemini explain the simple logic of Enigma!

1. Reproducing the 'rotor' (gears) where the circuit changes for each character

The greatest strength of Enigma was that 'even if you type the same character, it turns into a different character every time.' When you type 'aaa', the internal gears click the moment you type the first character, and the path of the electricity (the encryption rule) changes in real-time for the second and third characters.

In the program, we use the character position (i, representing which character it is) to drastically change the numerical value used for calculation every time we advance one character.

This reproduces Enigma's greatest trick: 'even if the same character 'a' is repeated, it becomes a completely different garbled character.'

2. Reproducing the 'reflector' where encryption and decryption are the same

Enigma had a brilliant part called a 'reflector' built in, which sent electrical signals back after they hit the end.

This gave it a unique property where 'if 'A' becomes 'B' under a certain setting, typing 'B' with the exact same setting will always return it to 'A',allowing it to perform 'encryption' and 'decryption' (reverting to the original) simultaneously in a single circuit.

In the program, this is reproduced using'XOR (Exclusive OR: ^)'a standard calculation in digital encryption.

It is a mathematical trick where 'if you apply a specific number to a certain number twice, it will always return to the original number.'

Note: This version supports multi-byte characters including Japanese, and it seems to have fixed the bug derived from the reflector mechanism—where the original Enigma could never convert a character into itself—by using XOR.


Encrypt and decrypt by clicking your bookmark with the text copied!

The content you have copied will switch!


🛠 How to use (Smartphone version)

1. Bookmark any page

First, bookmark any page, such as the one you are currently viewing.

2. Open "Edit"

On the bookmark bar, long-press the bookmark you just created and select "Edit".

3. Rewrite the content

In the settings screen that appears, change the following two items and save.

  • Name: (a name that is easy for you to understand)

  • URL: Delete the original URL entirely and paste the code.

It's easy, just press the bookmark!


📋 Paste this!

javascript:(function(){navigator.clipboard.readText().then(function(t){if(!t)return;var res='';for(var i=0;i<t.length;i++){res+=String.fromCharCode(t.charCodeAt(i)^((i+1)*12345&65535));}var isDe=/[ぁ-ん]/.test(res);var msg=isDe?%27%F0%9F%94%93【埩号元に戻したした】%27:%27%F0%9F%94%92【暗号化暗号にしたした】%27;navigator.clipboard.writeText(res).then(function(){alert(%27⚙%EF%B8%8F ゚ニグマ %27+msg+%27\n\nâ–Œ 凊理埌のテキスト â–Œ\n%27+res);});});})();

One-shot creation prompt!

※ Although the prompt was written for me, I haven't been able to test it this time💊

# 目的
iPadのSafariやスマホでも確実に動䜜する、「クリップボヌドのテキストを読み蟌み、゚ニグマ暗号機の仕様むンデックスに応じた動的シフトず反転可逆性を暡したロゞックで暗号化・埩号し、クリップボヌドに自動曞き戻しする」ブックマヌクレットを生成しおください。

# コヌドの制玄超厳守
1. 画面を汚さないDOM操䜜犁止ため、ペヌゞぞの芁玠远加は䞀切行わないこず。
2. 「navigator.clipboard.readText()」を甚いお、クリップボヌド内のテキストを盎接読み蟌むこず。空の堎合は凊理を抜けるこず。
3. ルヌプ凊理内で、文字のむンデックスiを甚いた動的な倀ず、文字コヌドcharCodeAtに察しおビット挔算のXOR^および「&65535」のマスクを行い、日本語や絵文字でも絶察に文字化け・クラッシュしない可逆暗号ロゞックを実装するこず。
4. 【重芁】ポップアップによる埅機時間を無くし、Safariのクリップボヌド曞き蟌み制限を回避するため、0か1かのモヌド遞択は行わずワンタップで凊理を完了させるこず。
5. 【重芁】暗号化か埩号かを自動刀別するため、倉換埌のテキストにひらがなが含たれるか/[ぁ-ん]/.test()を刀定し、含たれれば「🔓【埩号元に戻したした】」、含たれなければ「🔒【暗号化暗号にしたした】」ずアラヌトのタむトルを動的に切り替えるこず。
6. 倉換結果を「navigator.clipboard.writeText()」でクリップボヌドに曞き戻した盎埌の「.then()」の䞭で、䞊蚘で刀定したタむトルず凊理埌のテキストを「alert()」で衚瀺するこず。
7. 党䜓を「javascript:(function(){ ... })();」で包み、改行やスペヌスを排陀した【完党な1行のコヌド】ずしお出力するこず。
8. パヌセント蚘号やコヌド内での盎接の改行、async/awaitは䜿甚犁止。

# 出力圢匏
コヌドブロックに1行のコヌドだけを出力しおください。䜙蚈な解説文や挚拶は省いおください。

About this article!

Better late than never: Points to note regarding the Gemini 3-minute cooking article | Heron


Ask me anything! I will answer everything I can!

Is it set up? Trying out a note question box in someone else's garden unexpectedly! | Heron


I've started a membership!

I'm still feeling my way around, but I will accept requests/impossible demands/questions as much as possible!


I am participating! Please check it out😆


Paid article, this time it's a problem statement and a warning!

I wrote a summary article of my first month on note!All the important parts are available for free!
What I thought and what I did, I'm releasing it for a one-coin price to celebrate 500 followers!


I've placed all the props here!


☕ If you have some time, please check this out too!


If you like it, please give it a like and follow me!
For those visiting from outside of note, if you'd like, please press the heart button as it would be very encouraging 😊


いいなず思ったら応揎しよう