将一个数字包含在另一个数字中。 [英] Enconding a number to another number.

查看:114
本文介绍了将一个数字包含在另一个数字中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将一个数字(例如01566210201310)编码为完全不同的另一个数字,然后对其进行解码?

解决方案

请参阅我对此问题的评论(预定的引号)。



好​​的,编码:将数字乘以2.

解码:将结果除以2。 br />


因为你的号码似乎根本没有任何信息,而且你从不告诉任何人这个伎俩,没有人能够猜到。 :-)



如果这对你的目的不够好(谁知道它是什么?),请阅读加密和实现:

http://en.wikipedia.org/wiki/Cryptography [ ^ ],

http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx [ ^ ]。



-SA


如果你使用许多不同的可逆函数之一,你可以。

然而,它们都不会提供任何重要的安全性,因为它们都可以非常容易地被黑客攻击。

一种方法是使用XOR:

  lon g  original = 01566210201310L; 
long xor = 0x7F7F7F7F7F7F7F7FL;
long encode = original ^ xor;
long decode = encode ^ xor;
Console.WriteLine( original = {0},original);
Console.WriteLine( xor value = {0},xor);
Console.WriteLine( encoded = {0},encode);
Console.WriteLine( decoding = {0},decode);





哪个产生:

 original = 1566210201310 
xor value = 9187201950435737471
encoded = 9187200388520503713
decode = 1566210201310



但正如我所说,要弄清楚如何解决它并不困难。


Is it possible to encode a number (ex. 01566210201310) to another number completely different and then decode it?

解决方案

Please see my comment to this "question" (quotation marks intended).

OK, encoding: multiply the number by 2.
Decoding: divide the result by 2.

As your number seemingly carries no information at all, and you never tell anyone the trick, no one will be able to guess. :-)

If this is not good enough for your purpose (who knows what it is?), read on cryptography and implementations:
http://en.wikipedia.org/wiki/Cryptography[^],
http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx[^].

—SA


You can, provided you use one of many, many different reversable functions.
None of them however will provide any significant security, in that they can all be "hacked" extremely easily.
One way is to use an XOR:

long original = 01566210201310L;
long xor = 0x7F7F7F7F7F7F7F7FL;
long encode = original ^ xor;
long decode = encode ^ xor;
Console.WriteLine("original = {0}", original);
Console.WriteLine("xor value= {0}", xor);
Console.WriteLine("encoded  = {0}", encode);
Console.WriteLine("decoded  = {0}", decode);



Which produces:

original = 1566210201310
xor value= 9187201950435737471
encoded  = 9187200388520503713
decoded  = 1566210201310


But as I said, it isn''t difficult at all to work out how to break it.


这篇关于将一个数字包含在另一个数字中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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