当我输入“Hello World!”时 它被加密为“KNUUXWZXAUMX”如果我将其放入解密代码中,解密将返回为“HKRRUTWUXRJU”。
由于这是一个高中项目,因此需要一些必需的函数等。我必须在代码中使用函数、列表和循环。我稍后还会提出其他要求,例如要加密的大写字母、数字和标点符号。
我的代码是:
text = (input('Add some text: '))
def toList(text):
text.split()
return text
def encrypt(text):
shift = 3
text1 = text
encryption = ""
for x in text1:
xCode = ord(x)
xGuide = xCode - ord("A")
newGuide = (xGuide + shift) % 26
newCode = newGuide + ord("A")
newLetters = chr(newCode)
encryption = encryption + newLetters
print("encrypted text: ", encryption)
print("text:", text1)
encrypt(text)
cipherText = (input('Add some encrypted text: '))
def decrypt(cipherText):
shift = 3
cipherText1 = …Run Code Online (Sandbox Code Playgroud) 在我的理解中,异步只能处理I/O密集型任务,例如读写套接字或文件,而无法处理CPU密集型任务,例如加密和压缩。
所以在 Rust Tokio Runtime 中,我认为只需要用来spawn_blocking处理 CPU 密集型任务。但我看过这个回购协议,例子是
#[tokio_02::main]
async fn main() -> Result<()> {
let data = b"example";
let compressed_data = compress(data).await?;
let de_compressed_data = decompress(&compressed_data).await?;
assert_eq!(de_compressed_data, data);
println!("{:?}", String::from_utf8(de_compressed_data).unwrap());
Ok(())
}
Run Code Online (Sandbox Code Playgroud)
该库在压缩和异步 I/O 类型之间创建适配器。
我有 3 个问题:
等待压缩/解压缩的目的是什么?
这些适配器是必要的还是我对异步的理解错误?
我可以直接在 Tokio 多线程运行时进行压缩操作吗?像这样
async fn foo() {
let mut buf = ...;
compress_sync(&mut buf);
async_tcp_stream.write(buf).await;
}
Run Code Online (Sandbox Code Playgroud) 我在创建在 URL 中传递的加密字符串时遇到问题。我在解密后得到不正确的字符或错误。“输入数据不是一个完整的块”
这是我的类来加密和解密我的字符串:
public static class StringCipher
{
public static string Encrypt(string s)
{
return AesProvider(s, (aes, raw) =>
{
using var ms = new MemoryStream();
using (var cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(raw, 0, raw.Length);
}
return Encoding.UTF8.GetString(ms.ToArray());
});
}
public static string Decrypt(string s)
{
return AesProvider(s, (aes, raw) =>
{
using var ms = new MemoryStream();
using (var cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(raw, 0, raw.Length);
}
return Encoding.UTF8.GetString(ms.ToArray());
});
}
private …Run Code Online (Sandbox Code Playgroud) 下午好,我目前正在使用 JAVA 和 Quarkus 中的 api,在其中我通过 GET 方法接收 url 中使用 AES 加密的参数,问题是加密带有特殊字符,例如 +/ 现在读取服务将其作为路径的 url
这是我的 AES 加密代码、加密和解密方法,我将其用于加密:
package com.tmve.util;
import lombok.NoArgsConstructor;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.util.Arrays;
import java.util.Base64;
@NoArgsConstructor
public class EncryptUtil {
private static byte[] initializationVector = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
private static byte[] key;
private static SecretKeySpec secretKey;
public String encrypt(String input, String key)
throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidAlgorithmParameterException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException {
byte[] desKeyData = key.getBytes();
Cipher …Run Code Online (Sandbox Code Playgroud) 我们可以使用 ECC 加密大文件吗?或者就像 RSA 只适用于小文件一样?任何人都可以推荐一个用于 ECC Java 实现的好网站吗?
谢谢
我知道 IV 应该是随机的并与纯文本进行异或以开始加密。我的问题是,除了密钥之外,我是否还必须记住随机 IV 才能解密?
请告诉我们 Rijndael 对称加密算法的安全性。密钥存储在 Web 配置文件中。
I want to encrypt the id in URL I'll show my controller code and route. I've already used Crypt::encrypt($id); in my controller but it's not working properly so I've commented that line in my controller
this is my controller
public function update(TenderRequest $request,$id){
$tender = TenderMaster::findOrFail($id);
//Crypt::encrypt($id);
if($request->extend_date < $request->end_date || $request->bid_status > 0){
return 'unsuccess';
} else{
$transaction = DB::transaction(function () use($request,$tender,$id) {
$tender->extend_date = $request->extend_date;
$tender->remarks = $request->remarks;
$tender->update($request->all());
});
return 'BID '.$tender->ref_no.' Succesfully Updated';
}
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个程序可以加密特定位置的文件。我为此构建了一个函数,它循环遍历存储我的文件的列表的长度,因此如果我有 12 个文件,它将循环 12 次。然后我循环遍历我的目录,打开每个文件以读取和写入字节并加密它们的数据并将其写入文件。
该函数工作正常,但我的问题是我的函数需要很长时间才能完成,我不知道为什么。
有什么方法可以提高我的功能的性能吗?
加密功能:
此功能需要很长时间才能完成。
def encrypt(self):
for _ in range(0, len(files())):
for file in files():
try:
with open(file, 'rb+') as f:
plain_text = f.read()
cipher_text = self.token.encrypt(plain_text)
f.seek(0); f.truncate()
f.write(cipher_text)
except Exception as e:
print(f'{e}')
Run Code Online (Sandbox Code Playgroud)
文件功能:
def files(pattern='*'):
matches = []
for root, dirnames, filenames in chain(os.walk(desktop_path), os.walk(downloads_path), os.walk(documents_path), os.walk(pictures_path)):
for filename in filenames:
full_path = os.path.join(root, filename)
if filter([full_path], pattern):
matches.append(os.path.join(root, filename))
return matches
Run Code Online (Sandbox Code Playgroud) 我尝试在 Golang 中使用 AES 加密消息。
func main() {
key := "mysupersecretkey32bytecharacters"
plainText := "thisismyplaintextingolang"
fmt.Println("My Encryption")
byteCipherText := encrypt([]byte(key), []byte(plainText))
fmt.Println(byteCipherText)
}
func encrypt(key, plaintext []byte) []byte {
cphr, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
ciphertext := make([]byte, len(plaintext))
cphr.Encrypt(ciphertext, plaintext)
return ciphertext
}
Run Code Online (Sandbox Code Playgroud)
该函数返回: [23 96 11 10 70 223 95 118 157 250 80 92 77 26 137 224 0 0 0 0 0 0 0 0 0]
在该结果中,只有 16 个非零字节值。这意味着 Go 中的 AES …
encryption ×10
aes ×4
java ×2
python ×2
.net-core ×1
algorithm ×1
asynchronous ×1
base64 ×1
c# ×1
compression ×1
go ×1
laravel ×1
php ×1
quarkus ×1
rijndael ×1
rust ×1
rust-tokio ×1
symmetric ×1