投稿

Hey!!八郎
# 固定のS-Box(例として簡単な置換)
S_BOX = bytes([(x * 7) % 256 for x in range(256)])
def sbox_substitute(block):
return bytes(S_BOX[b] for b in block)
def xor_bytes(a, b):
return bytes(x ^ y for x, y in zip(a, b))
def shuffle(block):
# 単純なバイト入れ替え(例)
return block[1::2] + block[::2]
def encrypt_block(block, key, rounds=10):
for _ in range(rounds):
block = xor_bytes(block, key)
block = sbox_substitute(block)
block = shuffle(block)
return block
def pad(plaintext):
pad_len = 16 - len(plaintext) % 16
return plaintext + bytes([pad_len] * pad_len)
def encrypt(plaintext, key):
plaintext = pad(plaintext)
ciphertext = b""
for i in range(0, len(plaintext), 16):
block = plaintext[i:i+16]
ciphertext += encrypt_block(block, key)
return ciphertext
# 使用例
key = os.urandom(16)
plaintext = b"SecretMessage123"
ciphertext = encrypt(plaintext, key)
print("暗号文(16進):", ciphertext.hex())
話題の投稿をみつける

くるみ

MMだよ

こしょ

みかこ(
#ラブリカ・ヒナーノ #pw_jto
20250824 176BOX


ほたて

めぴ🍎

イ寺ぎ

^, ,^𓈒

ピギの
#語ろう校外学習

餃子
#お弁当あるある
お店におかずだけ先に詰めて置いてあって、炊飯ジャーのホカホカごはんを後入れするタイプのお弁当ってちょっと嬉しい
もっとみる 
関連検索ワード
