暗号技術入門
RSA
暗号化の公式
code:rsa
ModPow(平文, e, N) = 暗号文 // 暗号文とeとNから平文を複合するのは非常に難しい
code:rsa
package rsatest
import (
"testing"
"github.com/nobishino/goplayground/rsa"
)
func TestModPow(t *testing.T) {
title string
x int
y int
mod int
expect int
}{
{
title: "#1",
x: 3,
y: 3,
mod: 100,
expect: 27,
},
{
title: "#2",
x: 3,
y: 3,
mod: 10,
expect: 7,
},
{
title: "#3",
x: 4,
y: 4,
mod: 5,
expect: 1,
},
{
title: "mod = 221",
x: 2,
y: 5 * 29,
mod: 221,
expect: 2,
},
{
title: "mod = 221",
x: 3,
y: 5 * 29,
mod: 221,
expect: 3,
},
}
for , tt := range testcases {
t.Run(tt.title, func(t *testing.T) {
got := rsa.ModPow(tt.x, tt.y, tt.mod)
if got != tt.expect {
t.Errorf("expect %v, but got %v", tt.expect, got)
}
})
}
}
フェルマーの小定理
1. 5で割れない素数を4乗して5で割ると1が必ず余る
2. 4乗して1になるってことは5乗すると元に戻るということ
何乗かすると、元に戻るっていうのは暗号と復号という考え方に通じる。
なん乗したら元に戻るっていうのがカーマイケルの定理とか
一方向ハッシュ関数
なんで固定値になる?
弱衝突耐性
code:弱
x1,x2,x3,x4
x1を固定した時に、hash(h1) = hash(xn)となるようxnを見つけることが難しい。
強衝突耐性
code:強
hash(x_m) = hash(x_n) となるようなx_m x_nを見つけることさえできない
メッセージ認証コード