xor

Xor encryption in PHP

六眼飞鱼酱① 提交于 2019-12-05 03:45:15
I'm new to Xor encryption, and I'm having some trouble with the following code: function xor_this($string) { // Let's define our key here $key = ('magic_key'); // Our plaintext/ciphertext $text =$string; // Our output text $outText = ''; // Iterate through each character for($i=0;$i<strlen($text);) { for($j=0;$j<strlen($key);$j++,$i++) { $outText .= $text{$i} ^ $key{$j}; //echo 'i='.$i.', '.'j='.$j.', '.$outText{$i}.'<br />'; //for debugging } } return $outText; } When I run this it works for normal strings, like 'dog' but it only partially works for strings containing numbers, like '12345'.

algorithm to calculate XOR

别来无恙 提交于 2019-12-04 18:42:09
I want to calculate XOR of numbers from 0 to (n)^{1/2} - 1 with each of numbers from 0 to (n)^{1/2} - 1. i want to do this in O(n) time and cant use the XOR, OR, AND operations. If i know the XOR of X and Y, can i calculate XOR of X+1 and Y in constant time? As some have pointed out that XOR can be calculated in constant time using AND and NOT. How do i do the same for AND? How do i calculate AND of numbers from 0 to (n)^{1/2} - 1 with each of numbers from 0 to (n)^{1/2} - 1. i want to do this in O(n) time and cant use the XOR, OR, AND operations. P.S. - RAM model is being assumed here and

XOR using mathematical operators

拜拜、爱过 提交于 2019-12-04 10:09:04
问题 How can I implement XOR using basic mathematical operators like +,-,*,/ Update: Actually, I need to track change in two matrix having Boolean values. This can be done using XORing each value with corresponding value in other matrix. But, Lp_Solve library doesn't support XOR operation. Also, it accepts only linear equations. 回答1: (a − b)² This works because: (a − b)² = a * (a − b) + b * (b − a) Since multiplication in ℤ₂ is conjuction ( & ), and 1 - a is negation ( ! ), the above formula is

Determine numbers based on their sum and xor

假装没事ソ 提交于 2019-12-04 07:15:33
问题 If we know the sum and XOR of two numbers, then can we find out what are the two numbers? I am trying to resolve a problem and the above problem is a part of that. Although, I do have another solution for that problem but I still want a solution for this. 回答1: No. Example: SUM=7, XOR=7 Possible answers: a) 1, 6 b) 2, 5 c) 3, 4 Not enough information to decide which pair (a, b or c) is the original pair of numbers. 来源: https://stackoverflow.com/questions/25565626/determine-numbers-based-on

XOR use in MIPS Assembly

北慕城南 提交于 2019-12-04 07:02:36
问题 Okay, I'm pretty sure I've used up all variations of possible XOR use to exchange $s0 with $s1, however, I still can't get it to work! It's MIPS Assembly and I'm using MARS. Please could somebody provide me a solution? You will be greatly appreciated! 回答1: Did you try xor $s0, $s0, $s1 xor $s1, $s0, $s1 xor $s0, $s0, $s1 来源: https://stackoverflow.com/questions/15348977/xor-use-in-mips-assembly

Why swap with xor works fine in c++ but in java doesn't ? some puzzle [duplicate]

狂风中的少年 提交于 2019-12-04 04:16:41
Possible Duplicate: Why is this statement not working in java x ^= y ^= x ^= y; Sample code int a=3; int b=4; a^=(b^=(a^=b)); In c++ it swaps variables, but in java we get a=0, b=4 why? By writing your swap all in one statement, you are relying on side effects of the inner a^=b expression relative to the outer a^=(...) expression. Your Java and C++ compilers are doing things differently. In order to do the xor swap properly, you have to use at least two statements: a ^= b; a ^= (b ^= a); However, the best way to swap variables is to do it the mundane way with a temporary variable, and let the

binary format, bitwise operations exist? eg. <<16#7F, 16#FF>> bsl 1

别来无恙 提交于 2019-12-04 03:16:52
In erlang, there are bitwise operations to operate on integers, for example: 1&gt 127 bsl 1. 254 there is also the ability to pack integers into a sequence of bytes &lt&lt 16#7F, 16#FF &gt&gt is it possible, or are there any operators or BIFs that can perform bitwise operations (eg AND, OR, XOR, SHL, SHR) on binary packed data? for example (if bsl worked on binary packages - which it does not): 1&gt &lt&lt 16#7F, 16#FF &gt&gt bsl 1. &lt&lt 255, 254 &gt&gt Try out this way: bbsl(Bin,Shift) -> <<_:Shift,Rest/bits>> = Bin, <<Rest/bits,0:Shift>>. Using Erlang's unbounded integer sizes we can

EXCEL XOR multiple bits

╄→гoц情女王★ 提交于 2019-12-04 02:55:50
Okay I have two cells with a string of bits 0111010 and 0101011. I want to XOR the two together so that the resulting cell would be 0010001. I know you can use this for boolean values =OR(AND(A1,NOT(A2)),AND(A2,NOT(A1))) but it doesn't work for a string of bits. You need to use VBA to do this. If you open VBA, create a new Module and enter the function Public Function BITXOR(x As Long, y As Long) BITXOR = x Xor y End Function You can then use the DEC2BIN and BIN2DEC to convert from binary to decimal to run this function. For example: Cell A1 = 0111010 Cell A2 = 0101011 =DEC2BIN(BITXOR(BIN2DEC

TypeScript interface with XOR, {bar:string} xor {can:number} [duplicate]

喜夏-厌秋 提交于 2019-12-04 02:28:59
This question already has answers here : Closed 3 months ago . Does Typescript support mutually exclusive types? (4 answers) How do I say that I want an interface to be one or the other, but not both or neither? interface IFoo { bar: string /*^XOR^*/ can: number; } As proposed in this issue , you can use conditional types (introduced in Typescript 2.8) to write a XOR type: type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }; type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U; And you can use it like so: type IFoo = XOR<{bar: string;}, {can

XOR of two short integers

萝らか妹 提交于 2019-12-04 01:07:14
问题 I am calculating XOR of two short integers using XOR ^ operator in a traditional fashion. Below is the method- short a=197; short b=341; short y = (short) (a ^ b); However the XOR always returned integer but in my case inputs are short integer, that is why i am casting short to the XOR output. The XOR can be calculated in different manners (example: using BigInteger etc.) but performance wise (less time) which is the best for short integers? While keeping performance in mind, should i first