跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[问与答] 看到隔壁讨论密码学,乘机问一个折腾几天没看懂的问题

发表于

下面是简化的代码,描述的是解密的过程,我想知道对应加密的过程是怎么样的,没看懂这种逻辑的还原原理是什么

uint32_t descrypt(byte[] block, byte[] key) {
	// table_s5678 都是长度为 256 的四字节数组
    unsigned long table_s5[] = {0x21aa8423, 0x2fa1892a, 0x3dbc9e31, 0x33b79338,...};
    unsigned long table_s6[] = {0x5ee7493, 0xce07f9e, 0x17f26289, 0x1efc6984,...};
    unsigned long table_s7[] = {0xb33a6e73, 0xbe336078, 0xa9287265, 0xa4217c6e,...};
    unsigned long table_s8[] = {0xb4469bf0, 0xbf4b92fe, 0xa25c89ec, 0xa95180e2, ...}

    uint32_t ptr1 = 0;
    uint32_t ptr2 = 0;
    uint32_t ptr3 = 0;
    uint32_t ptr4 = 0;
    uint32_t ab;
   
    // 注意这是解密的逻辑
    // block 是明文,key 是密钥,两者各个字节先异或,然后在查表转换为四个字节的值
    ptr1 = table_s5[block[3] ^ key0[3]]; 
    ptr2 = table_s6[block[2] ^ key0[2]];
    ptr3 = table_s8[block[0] ^ key0[0]];
    ptr4 = table_s7[block[1] ^ key0[1]];
    // 面就是我不懂的地方:ab 是四个 long 的异或,怎么还原回四个 ptr ,如果不还原,对应加密又是怎么处理的
    ab = ptr1 ^ ptr2 ^ ptr3 ^ ptr4;
    return ab;

我对比了 AES 、DES 等算法里面关于 S 盒的实现,没有发现这么复杂的,主要就是一个自己转四个字节,四个字节转异或,怎么也没弄懂原理是什么。如果有知道的请指教。

更多:这个代码其实是苹果 FairPlay 的一部分,完整代码可以看这里( cycle 方法): https://github.com/FDH2/UxPlay/blob/c4fb40ee31b61b1b3b5ae406900af72edac2ca47/lib/playfair/omg_hax.c

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.