Java 实现波雷费密码算法示例代码 波雷费密码算法是一种对称式密码,是首种双字母取代的加密法。下面是 Java 实现波雷费密码算法示例代码的知识点总结: 1. 算法描述:波雷费密码算法是一种对称式密码,通过将明文信息和密文分离,使用双字母取代法对明文进行加密。 2. 算法步骤: (1) 从二维码 M05 中提取明文信息和密文,M05 格式:<xxx…xxx|yyy…yyy>,其中明文 xxx…xxx,密钥部分信息为 yyy…yyy 中的所有英文字母信息。 (2) 将提取的英文字母作为密匙,除去重复出现的字母,将密匙的字母逐个逐个加入 5×5 的矩阵内,剩下的空间将未加入的英文字母依A-Z 的顺序加入。(将 Q 去除) (3) 将要加密的讯息分成两个一组。如果组内的字母相同,将 X 加到该组的第一个字母后,重新分组。如果剩下一个字,也加入 X 字。 (4) 在每组中,找出两个字母在矩阵中的地方。如果两个字母不同行也不同列,在矩阵中找出另外两个字母,使这四个字母成为一个长方形的四个角。 (5) 若两个字母同行,取这两个字母右方的字母(若字母在最右方则取最左方的字母)。 (6) 若两个字母同列,取这两个字母下方的字母(若字母在最下方则取最上方的字母)。 (7) 新找到的两个字母就是原本的两个字母加密的结果。 (8) 取密文前三个字符与后三个字符(大写字母)作为对应6位的红外报警开启码。 3. 算法过程示例: 例如,二维码内容为:<hidethegold|play5fair9example>。首先,明文信息 hidethegold 和密匙 playfairexample,然后根据密钥形成5*5的矩阵,最后得到密文:“BM ND ZB XD KY GE”。 4. 具体代码实现: Java 代码实现波雷费密码算法的步骤,如下所示: ```java import sun.applet.Main; public class blf { public static void main(String[] args) { String s = "<hidethegold|play5fair9example>"; get_blf(s); } public static void get_blf(String ssss){ String eng = "ABCDEFGHIJKLMNOPRSTUVWXYZ"; String beg = ssss.replaceAll("[<>0-9]", ""); String []ss = beg.split("\\|"); String mw = ss[0].toUpperCase(); String str = ss[1].toUpperCase(); str = removeMethod(str); System.out.println(str); int bs = str.length() / 5; int ys = str.length() % 5; System.out.println(ys); System.out.println(bs); char[][] arr = new char[5][5]; for (int i = 0; i < bs; i++) { arr[i] = str.subSequence(i * 5, (i+1) * 5).toString().toCharArray(); } String yss = str.subSequence(bs*5, (bs*5+ys)).toString(); String other = eng.replaceAll("["+ str +"]", ""); System.out.println("other=" + other); arr[bs] = (yss + other.subSequence(0,(5-ys) )).toString().toCharArray(); int bs1 = bs + 1; //把余数补全 int oth = 25 - (bs1 * 5);//剩下的长度 other = other.subSequence((5 - ys), (oth + 5 - ys)).toString(); System.out.println("other=" + other); int c = 5 ; // ... } } ``` 波雷费密码算法是一种对称式密码,使用双字母取代法对明文进行加密。Java 实现波雷费密码算法示例代码可以帮助开发者更好地理解和实现波雷费密码算法。
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
- 粉丝: 3
- 资源: 933
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)