加密/解密 [英] Encryption / Decryption Sugestions

查看:113
本文介绍了加密/解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:

  $ str ='Hello World!'; 
encrypt($ str); //返回:abc123//固定长度的字符。
decrypt('abc123'); //返回:Hello World!//原始字符串的内容。

以上是在php中



可以任何一种计算机语言:



只要修正了,可以是固定号码



相同:32个字符,64个字符或X个字符。



我已经研究了一点,看起来很难或不可见。
但是你永远都不知道我以为可能会被worthed询问



如果你不要求你没有得到:) thnx


是的,如果您想要加密的字符数量有上限X ,这是可能的。只需使用任何加密算法加密,然后将结果填充到 X 字符。



如果没有上限,这是不可能的信息理论(你必须以某种方式存储无限数量的字符作为有限数量的[加密]字符,这是不可能的)。要了解原因,请查看鸽子原则


Is there a way to encrypt any string or file of any length and return a key with a fixed length.

e.g:

$str = 'Hello World!'; 
encrypt($str);//returns: "abc123"//a fixed length of characters.
decrypt('abc123');//returns: "Hello World!"//the contents of the original string.

above is in php

Can be any computer language:

Can be any fixed number as long as it's fixed

by fixed i mean always the same: 32 character, 64 characters or X characters.

I have researched a little and it looks like it's hard or imposible. but you never know i thought it might be worthed asking

if you dont ask you don't get :) thnx

解决方案

Yes, this is possible if there is an upper bound X for the number of characters you want to encrypt. Just encrypt using any encryption algorithm, then pad the result to X characters.

If there is no upper bound, this is impossible for reasons of information theory (you would have to somehow store an unlimited number of characters as a limited number of [encrypted] characters, which is not possible in general). To understand why, look up the pigeonhole principle.

这篇关于加密/解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆