如何多次运行加密程序来加强编码? [英] How do I run an encryption program multiple times to strengthen the encode?

查看:162
本文介绍了如何多次运行加密程序来加强编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码到目前为止。我需要运行代码的编码部分5次,然后解码编码相同的次数。我想出了如何对消息进行编码,但现在我无法弄清楚如何通过代码运行encode或decode变量来加强加密。

  public class Codes 
{
/ **
*使用存储在
*中的值的键对一条消息进行编码和解码。
* /
public static void main(String [] args)
{
int [] key = {7,6,5,2,8,5,8,6 ,4,1};
整数keyValue;
String encoded =,decoded =;
String message =队列对于编码消息很有用。
队列<整数> encodingQueue = new LinkedList< Integer>();
队列<整数> decodeQueue = new LinkedList< Integer>();

//加载密钥队列
(int scan = 0; scan< key.length; scan ++)
{
encodingQueue.add(key [scan] );
decodeQueue.add(key [scan]);
}

//编码消息
(int scan = 0; scan< message.length(); scan ++)
{
keyValue = encodingQueue.remove();
编码+ =(char)(message.charAt(scan)+ keyValue);
encodingQueue.add(keyValue);
}

System.out.println(Encoded Message:\\\
+ encoded +\\\
);


//解码消息
for(int scan = 0; scan< encoded.length(); scan ++)
{
keyValue = decodeQueue 。去掉();
decode + =(char)(encoded.charAt(scan) - keyValue);
decodeQueue.add(keyValue);
}

System.out.println(解码消息:\\\
+解码);
}


}

现在我收到这个输出:

 编码消息:
X {jwmx(gvf'{xgnzt& jpy& jpktlorh 'sju {fokw /

解码的消息:
队列对于编码消息很有用

为了完成这个程序,我需要输出如下:

 编码消息1:X {jwmx(gvf'{xgnzt& jpy& jpktlorh'sju {fokw / 
编码消息2:_?oyu} 0mzg。?} iv•|,nq?,orsytuvi.yow?kwq {0
编码消息3:f?t {}?8s〜h5 ?? k〜?? 2rr?2tt {〜| {zj5?ty?p?w?1
编码消息4:m?y} y?i< ?? m ??? 8vs?8yv??k??y {?u?}?2
编码消息5:t?〜??? H??jC ?? o ?????????????????$ 3
解码的消息5:m?y} ?? @ y?i&解码消息4:f?t {} 8s〜h5 ?? k〜?? 2rr?2tt {〜| { zj5•ty?p•w•1
解码的消息3:_?oyu} 0mzg。?} iv•|,nq?,orsytuvi.yow?kwq {0
解码的消息2:X {jwmx(gvf'{xgnzt& jpy& jpktlorh'sju {fokw /
解码的消息1:队列对于编码消息是有用的。

我估计为了做到这一点,我需要使用一个循环来运行encode并通过程序解码变量。然而,我无法弄明白如何发生这种情况。

解决方案

如果您为 encode() decode() operations:

 类代码{

public static void main(String [] args){
...
}

private static String encoding(String plaintext,Queue< Integer> encodingQueue){
...
}

private static String decode(String ciphertext,Queue< Integer> decodeQueue){
...
}

}

帮助?


Here is my code so far. I need to run the encode part of the code 5 times and then decode the encode the same number of times. I figured out how to encode the message but now I can't figure out how to run the "encode" or "decode" variable back through the code to strengthen the ecryption.

public class Codes
    {
        /**
         * Encode and decode a message using a key of values stored in
         * a queue.
         */
        public static void main(String[] args)
        { 
            int[] key = {7, 6, 5, 2, 8, 5, 8, 6, 4, 1};
            Integer keyValue;
            String encoded = "", decoded = "";
            String message = "Queues are useful for encoding messages.";
            Queue<Integer> encodingQueue = new LinkedList<Integer>();
            Queue<Integer> decodingQueue = new LinkedList<Integer>();

            // load key queues 
            for (int scan = 0; scan < key.length; scan++)
            {
                encodingQueue.add(key[scan]);
                decodingQueue.add(key[scan]);
            }

            // encode message
            for (int scan = 0; scan < message.length(); scan++)
            {
                keyValue = encodingQueue.remove();
                encoded += (char) (message.charAt(scan) + keyValue);
                encodingQueue.add(keyValue);
            }

            System.out.println ("Encoded Message:\n" + encoded + "\n");


            // decode message 
            for (int scan = 0; scan < encoded.length(); scan++)
            {
                keyValue = decodingQueue.remove();
                decoded += (char) (encoded.charAt(scan) - keyValue);
                decodingQueue.add(keyValue);
            }

            System.out.println ("Decoded Message:\n" + decoded);
        }


    }

as of right now I am receiving this output:

Encoded Message:
X{jwmx(gvf'{xgnzt&jpy&jpktlorh'sju{fokw/

Decoded Message:
Queues are useful for encoding messages.

In order to complete this program I need the output to look like this:

Encoded Message 1: X{jwmx(gvf'{xgnzt&jpy&jpktlorh'sju{fokw/ 
Encoded Message 2: _?oyu}0mzg.?}iv•|,nq?,orsytuvi.yow?kwq{0 
Encoded Message 3: f?t{}?8s~h5??k~??2rr?2tt{~|{zj5•ty?p•w•1 
Encoded Message 4: m?y}??@y?i<??m???8vs?8yv????~k<?y{?u?}?2 
Encoded Message 5: t?~•??H•?jC??o???>zt?>~x?????lC?~}?z???3 
Decoded Message 5: m?y}??@y?i<??m???8vs?8yv????~k<?y{?u?}?2 
Decoded Message 4: f?t{}?8s~h5??k~??2rr?2tt{~|{zj5•ty?p•w•1 
Decoded Message 3: _?oyu}0mzg.?}iv•|,nq?,orsytuvi.yow?kwq{0 
Decoded Message 2: X{jwmx(gvf'{xgnzt&jpy&jpktlorh'sju{fokw/ 
Decoded Message 1: Queues are useful for encoding messages.

I estimate that in order to make this happen I need to use a loop to run the "encode" and "decode" variables back through the program. However I cannot figure out how to make that happen.

解决方案

This will be easier if you use separate functions for the encode() and decode() operations:

class Codes {

  public static void main(String[] args) {
    ...
  }

  private static String encode(String plaintext, Queue<Integer> encodingQueue) {
    ...
  }

  private static String decode(String ciphertext, Queue<Integer> decodingQueue) {
    ...
  }

}

Does that help?

这篇关于如何多次运行加密程序来加强编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆