- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我用 Java 语言制作凯撒密码加密器,这是我的代码
private void encCaesar() {
tempCipher = "abcdef";
char[] chars = tempCipher.toCharArray();
for (int z = 0; z < tempCipher.length(); z++) {
char c = chars[z];
if (c >= 32 && c <= 126) {
int x = c - 32;
x = (x + keyCaesar) % 96;
if (x < 0)
x += 96;
chars[z] = (char) (x + 32);
}
}
ciphertext = chars.toString();
etCipher.setText(ciphertext);
}
我查不出有什么不对,但是密文是这样的405888,明文为“abcdef”,默认 key 为3,这是胡说八道
怎么了?
正确:
private void encCaesar() {
tempCipher = "abcdef";
char[] chars = tempCipher.toCharArray();
for (int z = 0; z < tempCipher.length(); z++) {
char c = chars[z];
if (c >= 32 && c <= 126) {
int x = c - 32;
x = (x + keyCaesar) % 96;
if (x < 0)
x += 96;
chars[z] = (char) (x + 32);
}
}
ciphertext = new String(chars);
etCipher.setText(ciphertext);
}
最佳答案
您应该使用 new String(chars)
而不是 chars.toString()
创建 ciphertext
:
ciphertext = new String(chars);
关于java - java语言中的凯撒密码密文失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13991379/
我的 SEAL v2.3.1 中有这些 SEAL 设置: seal::EncryptionParameters parms; parms.set_poly_modulus("1x^2048 + 1")
我有一些使用 Perl 的 Crypt::CBC 加密的密文我希望在其他地方解密的模块。 密文是使用 Crypt::CBC 的“简单”版本生成的。构造函数,即: use Crypt::CBC; $ci
我在使用 CryptoPP 时遇到问题。我正在使用 AES,并且想通过将其编码为 base64 来表示二进制密文。 我的问题是我在运行以下代码时随机出现断言错误: std::string encode
据我所知,RSA 加密的输出将等于 key 模数的长度(在本例中为 128 字节)。我的 RSA 加密代码是: public byte [] RSAEncrypter () throws Except
情况: 我正在尝试从我的谷歌云存储桶中下载和解密一些数据。 对于加密和解密,我使用: https://cloud.google.com/kms/docs/quickstart#decrypt_data
我使用此 openssl 命令创建了一条加密消息: openssl enc -aes-256-cbc -salt -in plaintext.txt -out cipher.enc 我尝试过 Cryp
我正在尝试将 AES 加密的 Java 代码复制到 Golang 中。但是我在 golang 中没有得到相同的输出 我试过下面的代码: Java 代码: package EncryptionTest;
我通过 java 、 BouncyCaSTLe Provider 实现这个使用 block 模式 = ECB 和填充模式 = PKCS7Padding 我注意到,如果我加密32字节长度的数据(例如61
我看过类似的主题,但我找不到与我正在努力实现的目标完全相符的解决方案。 我有一个密文,需要根据每个字母在文本中出现的频率进行简单的字母替换。我已经有一个规范化文本的功能(小写,没有非字母字符,没有,计
我是一名优秀的程序员,十分优秀!