expt.txt
上传用户:lyxiangda
上传日期:2007-01-12
资源大小:3042k
文件大小:5k
源码类别:

CA认证

开发平台:

WINDOWS

  1. Exponentiation
  2. For exponentiation, the MPI library uses a simple and fairly standard
  3. square-and-multiply method.  The algorithm is this:
  4. Input: a, b
  5. Output: a ** b
  6. s = 1
  7. while(b != 0)
  8.   if(b is odd)
  9.     s = s * a
  10.   endif
  11.   b = b / 2
  12.   x = x * x
  13. endwhile
  14. return s
  15. The modular exponentiation is done the same way, except replacing:
  16. s = s * a
  17. with
  18. s = (s * a) mod m
  19. and replacing
  20. x = x * x
  21. with
  22. x = (x * x) mod m
  23. Here is a sample exponentiation using the MPI library, as compared to
  24. the same problem solved by the Unix 'bc' program on my system:
  25. Computation of 2,381,283 ** 235
  26. 'bc' says:
  27. 4385CA4A804D199FBEAD95FAD0796FAD0D0B51FC9C16743C45568C789666985DB719
  28. 4D90E393522F74C9601262C0514145A49F3B53D00983F95FDFCEA3D0043ECEF6227E
  29. 6FB59C924C3EE74447B359B5BF12A555D46CB819809EF423F004B55C587D6F0E8A55
  30. 4988036A42ACEF9F71459F97CEF6E574BD7373657111648626B1FF8EE15F663B2C0E
  31. 6BBE5082D4CDE8E14F263635AE8F35DB2C280819517BE388B5573B84C5A19C871685
  32. FD408A6471F9D6AFAF5129A7548EAE926B40874B340285F44765BF5468CE20A13267
  33. CD88CE6BC786ACED36EC7EA50F67FF27622575319068A332C3C0CB23E26FB55E26F4
  34. 5F732753A52B8E2FB4D4F42D894242613CA912A25486C3DEC9C66E5DB6182F6C1761
  35. CF8CD0D255BE64B93836B27D452AE38F950EB98B517D4CF50D48F0165EF0CCCE1F5C
  36. 49BF18219FDBA0EEDD1A7E8B187B70C2BAED5EC5C6821EF27FAFB1CFF70111C52235
  37. 5E948B93A015AA1AE152B110BB5658CB14D3E45A48BFE7F082C1182672A455A695CD
  38. A1855E8781E625F25B41B516E77F589FA420C3B058861EA138CF7A2C58DB3C7504FD
  39. D29554D78237834CC5AE710D403CC4F6973D5012B7E117A8976B14A0B5AFA889BD47
  40. 92C461F0F96116F00A97AE9E83DC5203680CAF9A18A062566C145650AB86BE4F907F
  41. A9F7AB4A700B29E1E5BACCD6DCBFA513E10832815F710807EED2E279081FEC61D619
  42. AB270BEB3D3A1787B35A9DD41A8766CF21F3B5C693B3BAB1C2FA14A4ED202BC35743
  43. E5CBE2391624D4F8C9BFBBC78D69764E7C6C5B11BF005677BFAD17D9278FFC1F158F
  44. 1B3683FF7960FA0608103792C4163DC0AF3E06287BB8624F8FE3A0FFBDF82ACECA2F
  45. CFFF2E1AC93F3CA264A1B
  46. MPI says:
  47. 4385CA4A804D199FBEAD95FAD0796FAD0D0B51FC9C16743C45568C789666985DB719
  48. 4D90E393522F74C9601262C0514145A49F3B53D00983F95FDFCEA3D0043ECEF6227E
  49. 6FB59C924C3EE74447B359B5BF12A555D46CB819809EF423F004B55C587D6F0E8A55
  50. 4988036A42ACEF9F71459F97CEF6E574BD7373657111648626B1FF8EE15F663B2C0E
  51. 6BBE5082D4CDE8E14F263635AE8F35DB2C280819517BE388B5573B84C5A19C871685
  52. FD408A6471F9D6AFAF5129A7548EAE926B40874B340285F44765BF5468CE20A13267
  53. CD88CE6BC786ACED36EC7EA50F67FF27622575319068A332C3C0CB23E26FB55E26F4
  54. 5F732753A52B8E2FB4D4F42D894242613CA912A25486C3DEC9C66E5DB6182F6C1761
  55. CF8CD0D255BE64B93836B27D452AE38F950EB98B517D4CF50D48F0165EF0CCCE1F5C
  56. 49BF18219FDBA0EEDD1A7E8B187B70C2BAED5EC5C6821EF27FAFB1CFF70111C52235
  57. 5E948B93A015AA1AE152B110BB5658CB14D3E45A48BFE7F082C1182672A455A695CD
  58. A1855E8781E625F25B41B516E77F589FA420C3B058861EA138CF7A2C58DB3C7504FD
  59. D29554D78237834CC5AE710D403CC4F6973D5012B7E117A8976B14A0B5AFA889BD47
  60. 92C461F0F96116F00A97AE9E83DC5203680CAF9A18A062566C145650AB86BE4F907F
  61. A9F7AB4A700B29E1E5BACCD6DCBFA513E10832815F710807EED2E279081FEC61D619
  62. AB270BEB3D3A1787B35A9DD41A8766CF21F3B5C693B3BAB1C2FA14A4ED202BC35743
  63. E5CBE2391624D4F8C9BFBBC78D69764E7C6C5B11BF005677BFAD17D9278FFC1F158F
  64. 1B3683FF7960FA0608103792C4163DC0AF3E06287BB8624F8FE3A0FFBDF82ACECA2F
  65. CFFF2E1AC93F3CA264A1B
  66. Diff says:
  67. % diff bc.txt mp.txt
  68. %
  69. ------------------------------------------------------------------
  70. The contents of this file are subject to the Mozilla Public
  71. License Version 1.1 (the "License"); you may not use this file
  72. except in compliance with the License. You may obtain a copy of
  73. the License at http://www.mozilla.org/MPL/
  74. Software distributed under the License is distributed on an "AS
  75. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  76. implied. See the License for the specific language governing
  77. rights and limitations under the License.
  78. The Original Code is the MPI Arbitrary Precision Integer Arithmetic
  79. library.
  80. The Initial Developer of the Original Code is 
  81. Michael J. Fromberger <sting@linguist.dartmouth.edu>
  82. Portions created by Michael J. Fromberger are 
  83. Copyright (C) 1998, 2000 Michael J. Fromberger. All Rights Reserved.
  84. Contributor(s):
  85. Alternatively, the contents of this file may be used under the
  86. terms of the GNU General Public License Version 2 or later (the
  87. "GPL"), in which case the provisions of the GPL are applicable
  88. instead of those above.  If you wish to allow use of your
  89. version of this file only under the terms of the GPL and not to
  90. allow others to use your version of this file under the MPL,
  91. indicate your decision by deleting the provisions above and
  92. replace them with the notice and other provisions required by
  93. the GPL.  If you do not delete the provisions above, a recipient
  94. may use your version of this file under either the MPL or the GPL.
  95. $Id: expt.txt,v 1.1 2000/07/14 00:44:32 nelsonb%netscape.com Exp $