#FEATURE by stefan
authorStefan Vogel <sv@exept.de>
Wed, 29 Jan 2020 18:16:17 +0100
changeset 25213 3512890a4de5
parent 25212 af30e58b9fad
child 25214 2faf844125d9
#FEATURE by stefan class: LargeInteger added: #bitXored: changed: #bitXor:
LargeInteger.st
--- a/LargeInteger.st	Wed Jan 29 15:08:05 2020 +0100
+++ b/LargeInteger.st	Wed Jan 29 18:16:17 2020 +0100
@@ -333,6 +333,8 @@
     "Modified: / 8.5.1998 / 21:40:41 / cg"
 ! !
 
+
+
 !LargeInteger class methodsFor:'coercing & converting'!
 
 coerce:aNumber
@@ -1108,11 +1110,11 @@
     anInteger class ~~ LargeInteger ifTrue:[^ super bitXor:anInteger].
 
     (len1 := anInteger digitLength) > (len2 := self digitLength) ifTrue:[
-	newBytes := anInteger digitBytes copy.
-	newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1
+        newBytes := anInteger digitBytes copy.
+        newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1
     ] ifFalse:[
-	newBytes := digitByteArray copy.
-	newBytes bitXorBytesFrom:1 to:len1 with:anInteger digits startingAt:1
+        newBytes := digitByteArray copy.
+        newBytes bitXorBytesFrom:1 to:len1 with:anInteger digitBytes startingAt:1
     ].
     ^ (self class digitBytes:newBytes) compressed
 
@@ -1127,11 +1129,59 @@
      bigNum1 := 2 raisedToInteger:512.
      bigNum2 := 2 raisedToInteger:510.
      Time millisecondsToRun:[
-	1000000 timesRepeat:[
-	   bigNum1 bitXor:bigNum2.
-	]
+        1000000 timesRepeat:[
+           bigNum1 bitXor:bigNum2.
+        ]
      ]
     "
+
+    "Modified: / 29-01-2020 / 18:11:43 / Stefan Vogel"
+!
+
+bitXored:anInteger
+    "return the bitwise-or of the receiver and the argument, anInteger.
+     Here, a specially tuned version for largeInteger arguments
+     (to speed up some cryptographic code).
+     NOTE: This operation changes the receiver and doesn't compress the result!!"
+
+    |len1 len2 newBytes|
+
+    anInteger class ~~ LargeInteger ifTrue:[^ super bitXored:anInteger].
+
+    (len1 := anInteger digitLength) > (len2 := self digitLength) ifTrue:[
+        newBytes := anInteger digitBytes copy.
+        newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1.
+        digitByteArray := newBytes.
+    ] ifFalse:[
+        digitByteArray bitXorBytesFrom:1 to:len1 with:anInteger digitBytes startingAt:1.
+    ].
+    ^ self.
+
+    "
+     |bigNum1 bigNum2|
+
+     bigNum1 := 2 raisedToInteger:512.
+     bigNum2 := 2 raisedToInteger:510.
+     Time millisecondsToRun:[
+        1000000 timesRepeat:[
+           bigNum1 bitXored:bigNum2.
+        ]
+     ]
+    "
+
+    "
+     |bigNum1 bigNum2|
+
+     bigNum1 := 2 raisedToInteger:512.
+     bigNum2 := 2 raisedToInteger:510.
+     Time millisecondsToRun:[
+        1000000 timesRepeat:[
+           bigNum1 bitXor:bigNum2.
+        ]
+     ]
+    "
+
+    "Created: / 29-01-2020 / 17:50:54 / Stefan Vogel"
 !
 
 lowBit