首页 > 基础资料 博客日记

DES的Java初始置换部分实现

2023-08-03 18:50:10基础资料围观231

Java资料网推荐DES的Java初始置换部分实现这篇文章给大家,欢迎收藏Java资料网享受知识的乐趣

啦啦啦,我又来了,把进制问题解决后,其他就好搞了,刚刚把初始置换部分单独实现出来了!!!
一个立志成为一个java工程师的小菜鸡进化史。

 1 import java.util.Scanner;
 2 /**
 3  * @author :cjc
 4  * @date : 2022/7/23
 5  */
 6 public class helloword {
 7     public static void main(String[] args) {
 8         int[] mingwen = new int[64];
 9         Scanner in = new Scanner(System.in);
10         System.out.print("请输入16进制的明文:");
11         String kk = new String();
12         kk = in.next();
13         int len = kk.length();
14         while (len != 16) {
15             System.out.print("请重新输入16进制的明文:");
16             kk = new String();
17             kk = in.next();
18             len = kk.length();
19         }
20         char[] kk1 = kk.toCharArray();
21         int j = 0;
22         for (int i = 0; i < 16; i++) {
23             int a;
24             if (kk1[i] >= '0' && kk1[i] <= '9')
25                 a = kk1[i] - '0';
26             else
27                 a = kk1[i] - 'a' + 10;
28             int n[] = new int[4];
29             int f = 0;
30             while (a != 0) {
31                 n[f] = a % 2;
32                 a = a / 2;
33                 f++;
34             }
35             mingwen[j * 4] = n[3];
36             mingwen[j * 4 + 1] = n[2];
37             mingwen[j * 4 + 2] = n[1];
38             mingwen[j * 4 + 3] = n[0];
39             j++;
40         }
41         System.out.print("二进制为:");
42         for (int i = 0; i < 64; i++) {
43             if (i % 64 == 0) System.out.println();
44             System.out.print(mingwen[i]);
45         }
46         int[] IP = {58, 50, 42, 34, 26, 18, 10, 2,
47                 60, 52, 44, 36, 28, 20, 12, 4,
48                 62, 54, 46, 38, 30, 22, 14, 6,
49                 64, 56, 48, 40, 32, 24, 16, 8,
50                 57, 49, 41, 33, 25, 17, 9, 1,
51                 59, 51, 43, 35, 27, 19, 11, 3,
52                 61, 53, 45, 37, 29, 21, 13, 5,
53                 63, 55, 47, 39, 31, 23, 15, 7};
54         int[] mingwen_1 = new int[64];
55         for (int i = 0; i < 64; i++) {
56             mingwen_1[i] = mingwen[IP[i] - 1];
57         }
58         System.out.println();
59         System.out.print("初始置换后的结果:");
60         for (int i = 0; i < 64; i++) {
61             if (i % 64 == 0) System.out.println();
62             System.out.print(mingwen_1[i]);
63         }
64     }
65 }

欢迎各位大神进行指教!!!若有不足可在评论区留言讨论。


文章来源:https://www.cnblogs.com/CJCwin666/p/16524115.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!

标签:

相关文章

本站推荐

标签云