32位操作系统如何执行2^56模7?

发布于 2024-09-15 15:46:20 字数 66 浏览 1 评论 0原文

例如,如果是密码学中的 32 位操作系统,系统如何执行 2^56 模 7?

又是如何存储在内存中的呢?

How does the system perform the 2^56 modulo 7, if it's 32 bits operating system in cryptography for example?

And how it stored in memory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

浅忆 2024-09-22 15:46:21

模幂算法用于这种运算。这篇维基百科文章讲述了它是如何完成的:http://en.wikipedia.org/wiki/Modular_exponentiation

Modular exponentiation algorithms are used for this kind of operation. This Wikipedia article tells how it is done: http://en.wikipedia.org/wiki/Modular_exponentiation

滿滿的愛 2024-09-22 15:46:21

一般来说,如果您知道您的数字会变得非常大,您将使用 GMP(Gnu 多精度)之类的库来处理数学。如果您的手上有 2^32 个手指,它会执行您在纸上执行的操作。

Generally, if you know your numbers are going to get very big, you'll use a library like GMP (Gnu Multi-Precision) to handle the math. It does what you'd do on paper if you had 2^32 fingers on you hands.

梦冥 2024-09-22 15:46:21

哪个系统?哪种架构?

一般来说,在 32 位架构上,您会得到溢出结果。有些语言具有内置的、任意大的数字类型,可以处理这些计算。此类示例包括 Java 中的 BigDecimal 和 Python 中的内置 long int。

Which system? Which architecture?

Generally speaking on a 32-bit architecture, you are getting overflow results. Some languages have built-in, arbitrarily big, numeral types which can handle these calculations. Examples of this are BigDecimal in Java, and the built-in long ints in Python.

地狱即天堂 2024-09-22 15:46:21

使用 (a * b) mod c = ((a mod c) * (b mod c)) mod c。这意味着您基本上可以

  1. 从 x=1 开始
  2. 执行 x = (x*2)%7 56 次

One uses that (a * b) mod c = ((a mod c) * (b mod c)) mod c. That means that you can basically do

  1. start with x=1
  2. Do x = (x*2)%7 56 times
独留℉清风醉 2024-09-22 15:46:21

我认为你的术语有点混乱。

32 位操作系统或 32 位体系结构是一种机器地址限制为 32 位的操作系统。对于 32 位体系结构来说,具有对 64 位整数和/或 64 位浮点数进行运算的算术指令并不罕见。

因此,具有 32 位架构(并运行 32 位操作系统)的机器很可能会使用 64 位算术并将结果作为 64 位 long存储在内存中long long 使用 2 个连续的 32 位字。

I think your terminology is a bit confused.

A 32 bit operating system or 32-bit architecture is one in which machine addresses are limited to 32 bits. It is not at all unusual for a 32 bit architecture to have arithmetic instructions that operate on 64 bit integers and / or 64 bit floating point numbers.

So, it is quite likely that a machine with a 32 bit architecture (and running a 32 bit operating system) would use 64 bit arithmetic and store the result in memory as a 64 bit long or long long using 2 consecutive 32 bit words.

我最亲爱的 2024-09-22 15:46:21

还要添加其他答案,这些答案很好地解释了 32 int 和模乘逆,以及什么不是

我将解释什么是 32 位 CPU

32 位 CPU 正如大多数人所知道的那样,是与地址总线大小有关
这是可用地址的数量,例如在 x86(常见桌面 CPU [AMD、Intel])处理器上
这允许 2^32 字节的地址空间或 4G​​B 这通常在可寻址硬件和 RAM 之间划分,因此实际实现 64 位的原因 处理器是因为我们越来越接近 4G​​B RAM 限制

,顺便说一句,这种情况以前在 CPU 为 16 位时发生过

too add to other answers which do a good explanation of a 32 int and modular multiplicative inverse and what not

I'll explain what a the 32 bit CPU is

32 bit CPUs as most people know them as, is related to the Address bus size
this is that the amount of addresses available so for example on a x86 (your common desktop CPU [AMD, Intel]) processor
this allows 2^32 bytes of address space or 4GB this is usually split between the the addressable hardware and the RAM, so the reason for actually implementing a 64 bit Processor was because we were coming closer too the 4GB of RAM limit

as a side note this has previously happened when CPU's were 16bit

半寸时光 2024-09-22 15:46:20

关于任意精度算术

32 位操作系统不限制您拥有超过该大小的自定义类型。您的应用程序可以采用两个 32 位字并将其视为一个 64 位数字。大多数编程语言甚至有“双字”整数类型来简化问题。

您可以进一步扩展该概念以创建仅受有限内存量约束的任意精度积分数据类型。本质上,您有一个单词的数组,并将您的N位数字存储在该数组的单词的位中。

事实上,它是 32 位操作系统,其本身并不会限制您可以进行的数值计算。例如,Java long 是 64 位整型,无论它在何处运行。对于任意精度,java.math。 BigInteger 提高了赌注并提供了“无限字长”抽象。是的,这个“功能”甚至在 32 位操作系统中也可用(因为这从来都不是限制因素)。

另请参阅


关于整数环的数学

查找模乘逆模幂是一项常见的数学/算法任务在密码学领域。

您可能想要在此处使用的一种恒等式如下:

A * B (mod M) == (A (mod M)) * (B (mod M)) (mod M)

要找到x = 256 (mod 7),您不必必须首先计算并存储 256。如果您有 y = 255 (mod 7) -- 0..6 之间的数字 -- 您可以找到 x = y * 2(模 7)。

但是如何找到y = 255 (mod 7)?好吧,一种天真的方法是线性应用该过程,首先尝试找到 z = 254 (mod 7) 等等。这是线性求幂,但您可以通过执行例如通过平方求幂来做得更好。

也就是说,如果您有 28,您可以将其平方立即得到 216。然后您可以将其平方立即得到 232


总结

有许多复杂的数学算法适用于密码学,并且它是否在 32 位或 64 位操作系统上运行的程序中实现并没有直接关系。只要有足够的内存,计算机就能够执行任意精度的算术。

正是因为任意精度算术是一种有用的抽象,所以可以使用许多高性能库,以便您可以在预先存在的框架之上构建应用程序,而不必从头开始构建。

一些高级语言甚至内置了任意精度算术。例如,Python 在语言级别提供任意精度 intlong

On arbitrary-precision arithmetic

A 32-bit operating system does not limit you from having custom types that exceed that size. Your application can take two 32-bit words and treat it like one 64-bit number. Most programming languages even have a "double-word" integral type to simplify matters.

You can further extend the concept to create an arbitrary precision integral data type that is only bound by the amount of limited memory. Essentially you have an array of words, and you store your N-bit numbers in the bits of the words of this array.

The fact that it's a 32-bit operating system does not by itself limit the numeric computation that you can do. A Java long, for example, is a 64-bit integral type, regardless of where it's running. For an arbitrary precision, java.math.BigInteger ups the ante and provides "infinite word size" abstraction. And yes, this "feature" is available even in 32-bit operating systems (because that was never a limiting factor to begin with).

See also


On mathematics on the ring of integers

Finding modular multiplicative inverse or modular exponentiation is a common mathematical/algorithmic task in the fields of cryptography.

One identity that you may want to use here is the following:

A * B (mod M) == (A (mod M)) * (B (mod M)) (mod M)

To find x = 256 (mod 7), you do NOT have to first compute and store 256. If you have y = 255 (mod 7) -- a number between 0..6 -- you can find x = y * 2 (mod 7).

But how do you find y = 255 (mod 7)? Well, one naive way is to apply the process linearly and first try to find z = 254 (mod 7) and so on. This is a linear exponentiation, but you can do better by performing e.g. exponentiation by squaring.

That is, if you have say 28, you can square it to immmediately get 216. You can then square that to immediately get 232.


Summary

There are many sophisticated mathematical algorithms applicable to cryptography, and whether or not it's implemented in a program running on a 32-bit or a 64-bit operating system is not directly relevant. As long as enough memory is available, the computer is more than capable of performing arbitrary-precision arithmetic.

Precisely because arbitrary-precision arithmetic is a useful abstraction, many high-performance libraries are available, so that you can build your application on top of a pre-existing framework instead of having to build from the ground up.

Some high-level languages even have arbitrary-precision arithmetic built-in. Python, for example, provides arbitrary precision int and long at the language level.

盗琴音 2024-09-22 15:46:20
2**56 == 2**(28+28) == 2**28 * 2**28 == (2**28)**2
2**28 == 2**(14+14) == 2**14 * 2**14 == (2**14)**2
2**14 == 2**(7+7) == 2**7 * 2**7 == (2**7)**2
2**7 == 2**(3+3 +1) == 2**3 * 2**3 * 2 == (2**3)**2 * 2
2**3 == 2**(1+1 +1) == 2**1 * 2**1 * 2 == (2**1)**2 * 2

2**56 == (2**28)**2 == ((2**14)**2)**2 == (((2**7)**2)**2)**2
== (((2*(2**3)**2)**2)**2)**2 == (((2*(2*(2**1)**2)**2)**2)**2)**2

2**56 %7
== (((2*(2*(2**1)**2)**2)**2)**2)**2 %7
== (((2*(2*(2**1 %7)**2 %7)**2 %7)**2 %7)**2 %7)**2 %7
== (((2*(2*(2)**2 %7)**2 %7)**2 %7)**2 %7)**2 %7
== (((2*(2*4 %7)**2 %7)**2 %7)**2 %7)**2 %7
== (((2*(1)**2 %7)**2 %7)**2 %7)**2 %7
== (((2 %7)**2 %7)**2 %7)**2 %7
== ((2**2 %7)**2 %7)**2 %7
== ((4)**2 %7)**2 %7
== (16 %7)**2 %7
== (2)**2 %7
== 4 %7
== 4

so (2**56) % 7 == 4

您会注意到,我们从未处理过任何大数字(实际上最大的是 56)。

此外:

2**224 %7 == (2**56)**4 %7 == (4*4*4*4) %7 ==
((16%7) * (16%7)) %7 == (2*2) %7 == 4 %7 == 4

因此还有 2**896 %7 = 4 等(因为 896 = 4 * 224,其中 224 = 4 * 56 )。

2**56 == 2**(28+28) == 2**28 * 2**28 == (2**28)**2
2**28 == 2**(14+14) == 2**14 * 2**14 == (2**14)**2
2**14 == 2**(7+7) == 2**7 * 2**7 == (2**7)**2
2**7 == 2**(3+3 +1) == 2**3 * 2**3 * 2 == (2**3)**2 * 2
2**3 == 2**(1+1 +1) == 2**1 * 2**1 * 2 == (2**1)**2 * 2

2**56 == (2**28)**2 == ((2**14)**2)**2 == (((2**7)**2)**2)**2
== (((2*(2**3)**2)**2)**2)**2 == (((2*(2*(2**1)**2)**2)**2)**2)**2

2**56 %7
== (((2*(2*(2**1)**2)**2)**2)**2)**2 %7
== (((2*(2*(2**1 %7)**2 %7)**2 %7)**2 %7)**2 %7)**2 %7
== (((2*(2*(2)**2 %7)**2 %7)**2 %7)**2 %7)**2 %7
== (((2*(2*4 %7)**2 %7)**2 %7)**2 %7)**2 %7
== (((2*(1)**2 %7)**2 %7)**2 %7)**2 %7
== (((2 %7)**2 %7)**2 %7)**2 %7
== ((2**2 %7)**2 %7)**2 %7
== ((4)**2 %7)**2 %7
== (16 %7)**2 %7
== (2)**2 %7
== 4 %7
== 4

so (2**56) % 7 == 4

You'll note that we never dealt with any large numbers (indeed the largest was 56).

Furthermore:

2**224 %7 == (2**56)**4 %7 == (4*4*4*4) %7 ==
((16%7) * (16%7)) %7 == (2*2) %7 == 4 %7 == 4

And thus also 2**896 %7 = 4, etc (since 896 = 4 * 224, where 224 = 4 * 56).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文