共感で繋がるSNS
GRAVITY(グラビティ) SNS

投稿

Hey!!八郎

Hey!!八郎

import os

# 固定の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())
GRAVITY
GRAVITY13
話題の投稿をみつける
関連検索ワード

import os