Simple Columnar Transposition Technique(簡(jiǎn)單分欄式變換加密技術(shù))

          簡(jiǎn)單分欄式變換加密技術(shù):
          ? (1)將明文消息一行一行寫入預(yù)定長(zhǎng)度的矩形中
          ? (2)一列一列讀消息,但不一定按1、2、3列的順序,也可以按隨機(jī)順序,如2、3、1
          ? (3)得到的消息就是密文消息
          ? 注:密鑰為字符的話,就根據(jù)ASII碼的大小進(jìn)行組合。
          ? 實(shí)現(xiàn)的算法:按照排序好的數(shù)組bufClone的字符遍歷尋找對(duì)應(yīng)buf的字符的位置,然
          ? 后取出該位置整數(shù)倍的位置的字符
          ? SimpleColumar.java
          ?1?package?SimpleColumnarTransposition;
          ?2?import?javax.swing.JFrame;
          ?3?public?class?SimpleColumar?{
          ?4?????public?static?void?main(String[]?args)?{
          ?5?????????//實(shí)例化一個(gè)窗體
          ?6?????????SimpleColumnarFrame?frame?=?new?SimpleColumnarFrame();
          ?7?????????frame.setVisible(true);
          ?8?????????frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          ?9?????}????
          10?}
          11?
          12?

          ? SimpleColumnarFrame.java
          ??1?package?SimpleColumnarTransposition;
          ??2?
          ??3?import?java.awt.event.ActionEvent;
          ??4?import?java.awt.event.ActionListener;
          ??5?import?java.util.Arrays;
          ??6?
          ??7?import?javax.swing.*;
          ??8?
          ??9?@SuppressWarnings({?"static-access",?"static-access",?"static-access",?"static-access"?})
          ?10?public?class?SimpleColumnarFrame?extends?JFrame?{
          ?11?????JButton?btnKey?=?new?JButton();
          ?12?????JButton?btnReset?=?new?JButton();
          ?13?????JLabel?lbTest?=?new?JLabel();
          ?14?????JLabel?lbKey?=?new?JLabel();
          ?15?????JPasswordField?jpf?=?new?JPasswordField();
          ?16?????JTextField?tfDarkPass?=?new?JTextField();
          ?17?????JTextField?tfKey?=?new?JTextField();
          ?18?????char[]?arr;
          ?19?????byte[]?buf,bufClone;
          ?20?????
          ?21?????public?SimpleColumnarFrame()?{
          ?22?????????this.setSize(300,200);????????//設(shè)置窗體大小
          ?23?????????this.setTitle("簡(jiǎn)單變換柵欄加密法");
          ?24?????????this.setResizable(false);????//設(shè)置窗體大小不可變
          ?25?????????Init();????????//填充窗體內(nèi)容
          ?26?????}
          ?27?????
          ?28?????
          ?29?????private?void?makeBrightText()?{
          ?30?????????tfDarkPass.setEditable(true);
          ?31?????????arr?=?jpf.getPassword();?????//獲取明文
          ?32?????????buf?=?tfKey.getText().getBytes();?????//獲取密鑰,用ASII碼進(jìn)行比較
          ?33?????????bufClone?=?buf.clone();?????//克隆數(shù)組
          ?34?????????Arrays.sort(bufClone);?????????//?根據(jù)ASII碼排序
          ?35?????????reform();????????//重組字符
          ?36?????????tfDarkPass.setEditable(false);
          ?37?????}
          ?38?????
          ?39?????private??void?reform()?{
          ?40?????????/*?按照排序好的數(shù)組bufClone的字符遍歷尋找對(duì)應(yīng)buf的字符的位置,然
          ?41????????????后取出該位置整數(shù)倍的位置的字符*/
          ?42?????????char[]?a?=?new?char[arr.length];
          ?43?????????int?index?=?0;
          ?44?????????for(int?i=0;i<bufClone.length;i++)
          ?45?????????????for(int?j=0;j<buf.length;j++)?
          ?46?????????????????if(buf[j]==bufClone[i])?
          ?47?????????????????????for(int?k=0;k<arr.length;k++)?
          ?48?????????????????????????if((k+1)%buf.length==(j+1)%buf.length)
          ?49?????????????????????????????a[index++]?=?arr[k];????????
          ?50?????????String?str?=?new?String(a);
          ?51?????????tfDarkPass.setText(str);
          ?52?????}
          ?53?????
          ?54?????private?void?reset()?{
          ?55?????????tfDarkPass.setEditable(true);
          ?56?????????jpf.setText("");
          ?57?????????tfKey.setText("");
          ?58?????????tfDarkPass.setText("");
          ?59?????????tfDarkPass.setEditable(false);
          ?60?????}
          ?61?
          ?62?????private?void?Init()?{
          ?63?????????//????設(shè)置窗體內(nèi)容????????
          ?64?????????this.setLayout(null);
          ?65?????????lbTest.setText("輸入明文:");?
          ?66?????????lbTest.setBounds(30,?20,?80,?30);
          ?67?????????lbKey.setText("密鑰:?");
          ?68?????????lbKey.setBounds(30,?70,?80,?30);
          ?69?????????btnKey.setText("生成密文:");
          ?70?????????btnKey.setBounds(75,?110,?100,?30);????
          ?71?????????btnReset.setText("重置");
          ?72?????????btnReset.setBounds(5,?110,?60,?30);????
          ?73?????????jpf.setBounds(160,?20,?80,?30);
          ?74?????????jpf.setEchoChar('*');????????
          ?75?????????tfDarkPass.setBounds(190,?110,?80,?30);
          ?76?????????tfDarkPass.setEditable(false);
          ?77?????????tfKey.setBounds(160,?70,?80,?30);
          ?78?????????
          ?79?????????this.add(lbTest);
          ?80?????????this.add(jpf);
          ?81?????????this.add(lbKey);
          ?82?????????this.add(btnKey);
          ?83?????????this.add(btnReset);
          ?84?????????this.add(tfDarkPass);
          ?85?????????this.add(tfKey);
          ?86?????????
          ?87?????????btnKey.addActionListener(new?ActionListener(){
          ?88?????????????//觸發(fā)事件,生成明文
          ?89?????????????public?void?actionPerformed(ActionEvent?e)?{
          ?90?????????????????makeBrightText();????????????
          ?91?????????????}
          ?92?
          ?93?????????});
          ?94?????????
          ?95?????????btnReset.addActionListener(new?ActionListener(){
          ?96?????????????//觸發(fā)事件,生成明文
          ?97?????????????public?void?actionPerformed(ActionEvent?e)?{
          ?98?????????????????reset();????//????重置????
          ?99?????????????}
          100?
          101?????????});
          102?????}
          103?????
          104?}
          105?

          ?現(xiàn)實(shí)圖解:
          ?SimpleColumar.jpg
          ?輸入明文及密鑰,點(diǎn)擊生成密文按鈕,則產(chǎn)生相應(yīng)密文,重置,則重新填寫相關(guān)信息。
          ?

          posted on 2008-09-08 11:57 nonels 閱讀(826) 評(píng)論(0)  編輯  收藏 所屬分類: J2SE

          <2008年9月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(2)

          隨筆分類(16)

          隨筆檔案(16)

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 梧州市| 台东市| 当雄县| 盐边县| 潞西市| 营口市| 温泉县| 鄂尔多斯市| 惠州市| 二手房| 卢龙县| 桐乡市| 阳信县| 濮阳市| 吉林省| 安泽县| 麦盖提县| 汉阴县| 汝城县| 喀喇沁旗| 隆德县| 遵义市| 临泉县| 睢宁县| 兴海县| 安徽省| 东乌| 龙岩市| 施秉县| 嘉善县| 云阳县| 沙湾县| 绥滨县| 潍坊市| 普格县| 禄丰县| 剑河县| 花莲县| 静海县| 离岛区| 彰化县|