Java 将数据编码成用户类型的代码,就像一个老游戏';s密码保存系统
我试图搜索有关此的信息,但一定不知道正确的术语 用人类可读写的密码存储信息的最简单的方法是什么,用足够的填充使随机猜测的代码不太可能有效?与8位游戏机的密码保存系统不同 在我的特殊情况下,我希望能够在Java1.4.2下将三个无符号整数(每个无符号整数的最大长度大约为20位)编码成一个密码,并在web服务器上解密它们。我还考虑添加一个随机值或基于日期的值,以使密码唯一 代码可以使用数字、大小写混合字母和一些可能的简单符号,但可能应该排除像1lI和O0这样容易混淆的字符。由于用户需要输入,显然越短越好 谢谢Java 将数据编码成用户类型的代码,就像一个老游戏';s密码保存系统,java,cryptography,java1.4,human-readable,Java,Cryptography,Java1.4,Human Readable,我试图搜索有关此的信息,但一定不知道正确的术语 用人类可读写的密码存储信息的最简单的方法是什么,用足够的填充使随机猜测的代码不太可能有效?与8位游戏机的密码保存系统不同 在我的特殊情况下,我希望能够在Java1.4.2下将三个无符号整数(每个无符号整数的最大长度大约为20位)编码成一个密码,并在web服务器上解密它们。我还考虑添加一个随机值或基于日期的值,以使密码唯一 代码可以使用数字、大小写混合字母和一些可能的简单符号,但可能应该排除像1lI和O0这样容易混淆的字符。由于用户需要输入,显然越短
abcdefghjklmnpqrstuvwxyz012456789
表示base
n
中数据的k
位加上一个校验位所需的符号数为ceil(k*log(2)/log(n))+1
,对于k
=20位和n
=34位,仅为5个。您可以将属性编码为Base64。唯一的限制是您必须拥有固定大小的属性。您可能希望将MD5算法或类似算法应用于编码字符串
看看这个小飞贼用的是什么
}只是澄清一下,总共大约是60位(三个20位数字)。-谢谢我想这几乎是一个单独的问题,所以如果你不想回答,就不需要回答。但是你知道有什么简单的方法可以在不改变密码长度的情况下混淆密码,或者我可以在哪里找到适合这种情况的算法的信息?实际上,我想一些转置可能就足够了。这不是一个高安全性的项目。我会使用32个字符。然后每一个编码5位,将你的20位数字平均分割。下一个投票人能评论他们为什么不推荐这个吗?谢谢
public class Base64Encoder {
/**
* Base64 game properties encoded
* @param properties list of properties as Strings
* @return base64 encoded properties
*/
public String encodeProperties(List properties){
StringBuffer buffer = new StringBuffer();
Iterator iter = properties.iterator();
while(iter.hasNext()){
buffer.append(iter.next().toString());
}
return Base64.encodeBase64String(buffer.toString().getBytes());
}
/**
* Decodes a based64 properties
* @param propertiesSize list of Integer with each property size
* @param encodedProperties base64 encoded properties
* @return List of properties as String
*/
public List decodeProperties(List propertiesSize, String encodedProperties){
List decodedProperties = new ArrayList();
Iterator iter = propertiesSize.iterator();
String decoded = new String(Base64.decodeBase64(encodedProperties.getBytes()));
int current = 0;
while(iter.hasNext()){
Integer propertySize = new Integer(iter.next().toString());
String property = decoded.substring(current, current + propertySize.intValue());
decodedProperties.add(property);
current += propertySize.intValue();
}
return decodedProperties;
}
public static void main(String[] args){
String points = "1450";
String level = "12";
String lifes = "2";
Base64Encoder encoder = new Base64Encoder();
List properties = new ArrayList();
properties.add(points);
properties.add(level);
properties.add(lifes);
String encodedProperties = encoder.encodeProperties(properties); //MTQ1MDEyMg==
System.out.println(encodedProperties);
List propertiesSize = new ArrayList();
propertiesSize.add(Integer.valueOf(points.length()));
propertiesSize.add(Integer.valueOf(level.length()));
propertiesSize.add(Integer.valueOf(lifes.length()));
System.out.println(encoder.decodeProperties(propertiesSize, encodedProperties)); //[1450, 12, 2]
}