自定义加密的安全性如何?



我花了几周时间开发两种加密算法,不,我不使用它来加密任何敏感数据,我只想知道这些算法的安全性如何。(在说自定义加密不安全之前,请查看代码(

加密算法一:

import random
def encrypt(plainText, password):
plaintextList = []
passwordSeed = ''
key = 0
encryptedText = ''
count = 0
for i in plainText:
plaintextList.insert(count, str(ord(i)))
count += 1
for i in password:
passwordSeed += str(ord(i))
for i in range(10000):
random.seed(int(passwordSeed) + (i*1000))
key += random.randint(-1000000000, 1000000000)
for i in plaintextList:
encryptedText += str(int(i)*abs(key)) + '.'
return encryptedText

def decrypt(hashText, password):
splitHashText = []
passwordSeed = ''
key = 0
decryptedText = ''
splitHashText = hashText.split('.')
for i in password:
passwordSeed += str(ord(i))
for i in range(10000):
random.seed(int(passwordSeed) + (i*1000))
key += random.randint(-1000000000, 1000000000)
for i in splitHashText:
if i.isdigit():
decryptedText += chr(int(int(i)/abs(key)))
return decryptedText
while 1 == 1:
if input('Type e then enter to encrypt and d then enter to decrypt: ') == 'e':
print(encrypt(input('Encrypt: '),input('Password: ')))
else:
print(decrypt(input('Decrypt: '),input('Password: ')))

加密算法二:

def encrypt(plainText):
plainList = []
count = 0
total = 0
key = ''
for i in plainText:
plainList.insert(count,ord(i))
total += int(ord(i))
count += 1
for i in plainList:
key += str(i/total) + ';'
return total, key
def decrypt(hashedText, key):
keys = key.split(';')
letters = []
count = 0
for i in keys:
if i != '':
letters.insert(count, chr(int(float(hashedText)*float(i))))
count += 1
return ''.join(letters)
while 1 == 1:
if input('Type e to encrypt and d to decrypt: ') == 'e':
data = encrypt(input('String to encrypt: '))
print('Hashed text: '+ str(data[0]) + '   Key: ' + str(data[1]))
else:
print(decrypt(input("Hash: "), input("Key: ")))

如果你想测试它,可以在任何python IDE中运行代码。如果此加密是安全的,请随意使用该代码。

让我从Bruce Schneier的博客文章开始:

译艺术最独特的特征之一是每个人,即使是稍微熟悉它的人,都拥有强烈的信念,即他能够构建其他人无法破译的密码。

因此,如果你必须问,那么我敢说这意味着你对密码学的了解是有限的,不幸的是,这也意味着你的代码从一开始就是相当错误的,尤其是考虑到安全性。

只是想知道这些算法的安全性如何 如果要使用它们

快速浏览一下发布的代码让我说它充其量和凯撒密码一样弱。虽然实验和学习(显然(没有错,但你不应该将代码用于比这更严肃的事情。有由该领域专家设计的强大加密算法,并由该领域的其他专家证明和验证。有各种形式的现成实现。你的代码看起来像是试图重新发明轮子,而不知道一个合适的轮子应该是什么样子。而且一个人可能会从带有方形轮子的自行车上摔得很重......

最后,让我推荐西蒙·辛格(Simon Singh(的《密码书》(Code Book(——这本书将帮助你意识到字段密码学是多么复杂,以及你需要学习多少东西——这本书是为非专家写的,所以你实际上应该从中受益并从中学到很多东西。真的推荐给任何人(非技术人员(。

PS:还有 https://crypto.stackexchange.com/

虽然我自己曾经修补过加密,但最终你必须问你是否真的相信你的想法。问题出在,

在说自定义加密不安全之前,请查看代码

举证责任在你身上。您必须证明您的加密是安全的。

例如,RSA有这样的证明。

所以没有。您的加密不安全,因为您尚未证明这一点。不过,我不想阻止您尝试!我玩得很开心,弄乱这样的事情。

在说自定义加密不安全之前,请查看代码

自定义加密几乎从来都不安全;有充分的理由认为答案是迄今为止您遇到此类问题的最常见答案。看起来安全的东西通常在算法、实现中具有可利用的属性,或者只是因为它们很容易被蛮力破解。

你真正遇到的最大问题是,世界上很少有人有资格评估加密算法是否真的安全,我怀疑那些不能在SO上闲逛的人。

最新更新