Skip to content

Instantly share code, notes, and snippets.

@trivialfis
trivialfis / HMM.py
Created December 22, 2018 19:10
Re-implementation of "A Revealing Introduction to Hidden Markov Models".
'''
Copyright (c) 2018 jm.yuan@outlook.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@trivialfis
trivialfis / 4.17.md
Last active October 11, 2017 15:16
展示 DES 解密过程实质是加密过程的逆过程。

DES 与 Feistel Cipher Structure 的不同点

DES是在 Feistel Cipher Structure (FCS) 基础上构建的加密算法。在加密过程中, DES在FCS开始前添加 Initial Permutation 和对原来 FCS 的输出添加了 逆向的 Initial Permutation。 同时,也通过circular shift 和 permute 实现了 SubKey 的生成。

解密是加密的逆过程

基于上述所说的不同点, 同时已知 FCS 本身解密是加密的逆过程,那么我们只要证明 DES 跟 FCS 的不同点不会对算法带来影响即可。

Permutation

首先展示 $IP$$IP^{-1}$ 不会对算法带来影响。 把 Permutation 操作看作一个由 Permutation Matrix 实现的线性变换, 由 Permutation Matrix 本身的性质可知 $PP^{-1} = I$, 也就是加密过程结束时的 preoutput 和解密过程开始时经过 $P^{-1}$ 后的密文是一样的。

Subkey