【发布时间】:2020-04-13 22:39:02
【问题描述】:
tldr:公式 x / (1 * 1) 减去数百万亿。为什么?
大家好!我对python很陌生,在从头开始制作python消息加密器时,(我知道,有更简单的方法可以制作消息编码器。我只是为了体验和乐趣而制作它)非常简单的乘法和除法问题似乎非常不准确.基本上,我的编码器通过将输入字符串中的所有字符转换为数字,然后将数字乘以两个单独的用户提供的键来工作。我一直在将所有键设置为 1 进行测试,并且编码工作正常;解码是问题。我的公式是:
编码:
String = String * Key1 * Key2 #Both keys are set to 1
解码:
String = String / (Key1 * Key2) #Again, both keys are set to 1, so in theory it should just spit the string back out.
当我输入 370190160220170180330190140310320 时,我得到 370190160220170177391212613337088。
370190160220170180330190140310320
370190160220170177391212613337088
因此,等效于 x / (1 * 1) 的公式显然意味着减去多少万亿。这里发生了什么?就像我说的,我是 python 的新手,所以这个问题的解决方案可能非常简单,但我就是想不通。
【问题讨论】:
-
/是浮点数,浮点数精度有限。
标签: python encoding division multiplication decoding