1

最近、ゼルダの伝説オラクル オブ シーズンズとオラクル オブ エイジズのゲームをリプレイしていて、秘密のコードが気になりました。これを Python または Java で再作成して、どのように機能するかを確認したいと思います。

問題は、それを行う方法が見つからないことです。どのようにエンコード システムを作成しますか?

  1. 入力した最初の「リンク」コード (ゲームで名前が付けられているように、labrynna または holodrum の秘密) に依存するため、他の誰かからコードを盗むことはできません。
  2. タイプミスを検出します。foob​​ar の代わりに fobaz と入力すると、コードが間違っていることが検出されます。
  3. 大量の (かなりの量の) 情報を保存できます。また、ゲームのように 5 ~ 20 文字です (これは必須ではありませんが、あれば便利です)。

注: 私はオラクルのゲーム用のジェネレーターを作成しようとしているのではなく、オラクルのゲームのもののように見える秘密を生成して読み取るためのコードだけです。

この質問のプログラミング範囲は、オラクル ゲームの秘密のコードを模倣するシステムを使用して情報をエンコードおよびデコードする方法です。

4

1 に答える 1

1

シリアライゼーション + エンコーディングの形式だと思います。

基本的に、さまざまな秘密の値を含むバイト配列を生成する必要があります (これは、ほとんどのバイナリ プロトコルの記述方法です)。次に、各バイトを対応する文字 (またはそれ以上) にエンコードして、出力 "文字列" を読み取れるようにします。Python でデータをバイト配列にシリアル化する方法のサンプルを次に示します。

プレイヤー情報

player_name = "Robert"

player_stats = {
    "health": 200,
    "mana": 150,
    "has_sword": True,
    "has_arrows": False,
    "has_shovel": True,
    "dungeon1_complete": True
}

シリアライゼーション情報の設定

# If these can be greater than 255, they must be stored across multiple bytes - extra work
byte_attribs = ["health", "mana"]

bit_attribs = ["has_sword", "has_arrows", "has_shovel", "dungeon1_complete"]

player_name_max_length = 7
byte_attrib_offset = player_name_max_length
bit_attrib_offset = byte_attrib_offset + len(byte_attribs)

secret_storage = bytearray(bit_attrib_offset + len(bit_attribs))

assert(len(player_name) <= player_name_max_length)

シリアル化を実行する

# Serialize Player Name
secret_storage[:player_name_max_length] = player_name.rjust(player_name_max_length)

# Serialize attributes:
for idx, attrib in enumerate(byte_attribs):
    secret_storage[byte_attrib_offset + idx] = player_stats[attrib]

for idx, attrib in enumerate(bit_attribs):
    byte_offset = idx // 8  # attribs 0-7 go in byte 0, etc.
    bit_offset = idx % 8

    # Bit manipulation examples: http://wiki.python.org/moin/BitManipulation
    current_byte = bit_attrib_offset + byte_offset
    if player_stats[attrib]:
        mask = 1 << bit_offset
        secret_storage[current_byte] = secret_storage[current_byte] | mask
    else:
        mask = ~(1 << bit_offset)
        secret_storage[current_byte] = secret_storage[current_byte] & mask

個々の値を取得する

print "Storage array encoded as ascii:", secret_storage

# Access name:
print "Name:", secret_storage[:player_name_max_length].lstrip()
# >>> Name: Robert

# Access byte values:
attrib_idx = byte_attribs.index("mana")
print "Mana level:", secret_storage[byte_attrib_offset + attrib_idx]
# >>> Mana level: 150

# Access bit flags:
attrib_idx = bit_attribs.index("dungeon1_complete")
print "Completed Dungeon 1:", bool(secret_storage[bit_attrib_offset + (attrib_idx // 8)] & (1 << attrib_idx % 8))
# >>> Completed Dungeon 1: True
于 2013-08-11T01:07:44.890 に答える