有没有一种方法可以将一个字符串随机分成不同的字符串数组,并返回相同的字符串 [英] is there a way randomly separate a string into different string array and get back same same string

查看:73
本文介绍了有没有一种方法可以将一个字符串随机分成不同的字符串数组,并返回相同的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有

String Text = "ABCDEFGHIJKLMNOPQ";

通过一些代码进入

String[] text1 = "AOCN";
String[] text2 = "JQBF";
String[] text3 = "DMG";
String[] text4 = "HPI";
String[] text5 = "KEL";

然后输入一些代码将其恢复为

then some code to get it back to

字符串文本= ABCDEFGHIJKLMNOPQ;

String Text = "ABCDEFGHIJKLMNOPQ";

这可能吗?
我要实现的目标是将溢出的字符随机存储到5个不同的字符串数组中,并使用代码将其恢复为原始文本

is this possible? what I am trying to achieve is random storing the spilt character into 5 different String Array and use code to revert it back to it original text

推荐答案

假设对数组进行字母随机分配的请求是因此是可逆的伪随机(或表面上任意)分配,那么这样做的一种技术是本质上使用换位密码

Assuming that the request for a "random" allocation of letters to arrays is for a pseudo-random (or, perhaps, a superficially arbitrary) allocation that is therefore reversible, one technique to do this would be to essentially use a transposition cipher.

然后,该算法将类似于:

The algorithm would then be something like:


  1. 运行转置密码输入的文本。

  2. 将转置后的文本拆分为数组。

原始文本将然后通过反转两个步骤即可获得。

The original text would then be obtained by reversing the two steps.

(编辑)

换位密码密钥可以由来自<$的伪随机数流组成c $ c> 1 到 n ,其中 n 是其中输入字符串将被分割。因此,扩展算法如下:

The transposition cipher key could consist of a stream of pseudo-random numbers from 1 to n where n is the number of strings into which the input string is to be split. Thus, an expanded algorithm would read as follows:


  1. 生成伪随机数列表, p m 的code>,其中 m 是输入字符串的长度。

  2. 对于所有 i ,在输入字符串中分配第 i 个字母到输出字符串号 p [i]

  1. Generate a list of pseudo-random numbers, p, of length m, where m is the length of the input string.
  2. For all i, assign the ith letter in the input string to the output string number p[i].

重新组合原始字符串:


  1. 对于所有 i ,获取 i 字符串号 p [i] 中下一个未使用的字母中的第一个字母。

  1. For all i, obtain the ith letter in the string from the next unused letter in string number p[i].

这篇关于有没有一种方法可以将一个字符串随机分成不同的字符串数组,并返回相同的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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