Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
デデンネでもわかる RSA
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
QUANON
August 27, 2020
Programming
66
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
デデンネでもわかる RSA
QUANON
August 27, 2020
More Decks by QUANON
See All by QUANON
文字を数えるのも楽じゃない
quanon
0
110
Other Decks in Programming
See All in Programming
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
160
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
ChromeでローカルLLM
ryu1013
0
140
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
280
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
430
golang-bob.pdf
iwatsukayura
0
130
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
Railsバージョンを4倍にした話
optim
0
440
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
650
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Featured
See All Featured
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Why Our Code Smells
bkeepers
PRO
340
58k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
890
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
We Are The Robots
honzajavorek
0
400
For a Future-Friendly Web
brad_frost
184
10k
Scaling GitHub
holman
464
140k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
520
GitHub's CSS Performance
jonrohan
1033
470k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Abbi's Birthday
coloredviolet
4
10k
Navigating Weather and Climate Data
rabernat
0
560
Transcript
ͰΘ͔Δ RSA σσϯω
ࣗݾհ • Shinpei Noda (@quanon_jp) • Money Forward, Inc. •
αʔόαΠυΤϯδχΞ • Ruby/Rails • ಡॻ͕େ͖ • ଜ্य़थओٛऀ
RSA ͱ • ͘ΘΕ͍ͯΔެ։伴҉߸ΞϧΰϦζϜ • ެ։伴ͱݺΕΔ伴Ͱ҉߸Խ͠ɺൿີ伴ͱݺΕΔ伴Ͱ෮߸͢Δ • σδλϧॺ໊ʹ͏͜ͱͰ͖Δ • SSH
ͷެ։伴ೝূͷͨΊʹ id_rsa, id_rsa.pub ͱ͍͏伴ϖΞΛ࡞ͬͨ ͜ͱ͕͋ΔͷͰ
҉߸ͷΞϧΰϦζϜͬͯ ͳΜ͔ͩͦ͠͏……
େৎʂ ϙέϞϯͰ͔Δ͘Β͍ γϯϓϧʂ
҉߸Խɾ෮߸ • ҉߸Խ: • ෮߸: • ެ։伴: • ൿີ伴: ciphertext
= plaintextE mod N plaintext = ciphertextD mod N {E, N} {D, N}
伴ϖΞ • ެ։伴: , ൿີ伴: • ͜ͷ ΛٻΊΔʹ 2 ͭͷૉ
Λ͏ • ࡐྉͨͬͨ͜Ε͚ͩʂ {E, N} {D, N} E, D, N p, q
伴ϖΞ • • ͦΕͧΕϥϯμϜͰेʹେ͖͍ૉ • • ͱ࠷খެഒ (Least Common Multiple)
ͷ͜ͱ N = p ⋅ q p, q L = lcm(p − 1,q − 1) lcm
伴ϖΞ • ( ) • ͱ࠷େެ (Greatest Common Divisor) ͷ͜ͱ
• ͭ·Γ ޓ͍ʹૉͳҙͷ • ( ) • ͭ·Γ ͱͷੵͷ༨͕ 1 ͱͳΔҙͷ gcd(E, L) = 1 1 < E < L gcd E, L (E ⋅ D) mod L = 1 1 < D < L D E
RSA ͷ҆શੑ • ൿີ伴ΛΘͣʹ҉߸Խͷࡍͷ ͱ͍͏ࣜ Λղ͍ͯ҉߸จ (ciphertext) ͔Βฏจ (plaintext) ΛಘΔͷ͍͠
• ࢄର Λղ͘ͷແཧήʔ • ͷ ΛૉҼղͯ͠ ΛಘͯɺͦΕ͔Β ΛٻΊΔͱ͍ ͏ղಡํ๏ߟ͑ΒΕΔ͕…… • ඇৗʹେ͖ͳ Λ ૉҼղ ͢Δͷແཧήʔ ciphertext = plaintextE mod N N = p ⋅ q N p ⋅ q D N
Ruby Ͱ࣮ͯ͠ΈΑ͏ # 平文 plain_text = '夜は短し歩けよ乙女' plain_integers = plain_text.each_codepoint
plain_integers.to_a #=> [22812, 12399, 30701, 12375, 27497, 12369, 12424, 20057, 22899]
Ruby Ͱ࣮ͯ͠ΈΑ͏ require 'prime' # 2 つの素数を選ぶ。 # 本当は十分に大きい素数である必要がある。 p,
q = *Prime.each(10_000).to_a.sample(2) #=> [4583, 151]
Ruby Ͱ࣮ͯ͠ΈΑ͏ n = p * q #=> 692033 l
= (p - 1).lcm(q - 1) #=> 343650 e = (2...l).find { |i| i.gcd(l) == 1 } #=> 7 d = (2...l).find { |i| (e * i) % l == 1 } #=> 49093
Ruby Ͱ࣮ͯ͠ΈΑ͏ [e, n] # 公開鍵 #=> [7, 692033] [d,
n] # 秘密鍵 #=> [49093, 692033]
Ruby Ͱ࣮ͯ͠ΈΑ͏ # 公開鍵 [e,n] で暗号化 encrypted_integers = plain_integers.map {
|i| i.pow(e, n) } #=> [79745, 636262, 150603, 188308, 444550, 549324, 383889, 180314, 632474] # 暗号文 (無理やり文字列にしてみる) cipher_text = encrypted_integers.map(&:chr).join #=> "\u{13781}\u{9B566} \u{6C886}\u{861CC}\u{5DB91} \u{9A69A}"
Ruby Ͱ࣮ͯ͠ΈΑ͏ # 秘密鍵 [d, n] で復号 decrypted_intergers = encrypted_integers.map
{ |i| i.pow(d, n) } #=> [22812, 12399, 30701, 12375, 27497, 12369, 12424, 20057, 22899] # 平文 decrypted_intergers.map(&:chr).join #=> "夜は短し歩けよ乙女"
খωλ: Integer#pow ʹ͍ͭͯ 123_456_789 ** 999_999_999 % 7_777 # warning:
in a**b, b may be too big #=> NaN 123_456_789.pow(999_999_999, 7_777) #=> 4453
·ͱΊ • RSA ͷΞϧΰϦζϜඇৗʹγϯϓϧ ✨ • ֶతͳੑ࣭ʹΑͬͯ҆શੑΛอূ͍ͯ͠Δ • ݁ߒ͞Μͷʰ҉߸ٕज़ೖʱΛಡ͏