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 ð
