Phạm Trần Minh Hiếu
@2280600972
Cách giải bài trên ( C/C++)
include <stdio.h>
int main() {
int n, S;
while (scanf("%d", &n) == 1)
{
S = 0;
for (int i = 1; i <= n; i++)
{
S = S + i;
}
printf("%d\n",S);
}
return 0;
}
Trả lời
0 Phản hồi
C
Nguyễn Đức Cường
@2380600256
Solution sum N variation
import rsa, os
if not os.path.exists('cipher/rsa/keys'):
os.makedirs('cipher/rsa/keys')
class RSACipher:
def __init__(self):
pass
def generate_keys(self):
(public_key, private_key) = rsa.newkeys(1024)
with open('cipher/rsa/keys/publicKey.pem', 'wb') as p:
p.write(public_key.save_pkcs1('PEM'))
with open('cipher/rsa/keys/privateKey.pem', 'wb') as p:
p.write(private_key.save_pkcs1('PEM'))
def load_keys(self):
with open('cipher/rsa/keys/publicKey.pem', 'rb') as p:
public_key = rsa.PublicKey.load_pkcs1(p.read())
with open('cipher/rsa/keys/privateKey.pem', 'rb') as p:
private_key = rsa.PrivateKey.load_pkcs1(p.read())
return private_key, public_key
def encrypt(self, message, key):
return rsa.encrypt(message.encode('ascii'), key)
def decrypt(self, ciphertext, key):
try:
return rsa.decrypt(ciphertext, key).decode('ascii')
except:
return False
def sign(self, message, key):
return rsa.sign(message.encode('ascii'), key, 'SHA-1')
def verify(self, message, signature, key):
try:
return rsa.verify(message.encode('ascii'), signature, key,) == 'SHA-1'
except:
return False
Trả lời
0 Phản hồi
Bạn cần đăng nhập để tham gia thảo luận
Đăng nhập ngay