xor

Simple XOR encryption routine in C/C++

爷,独闯天下 提交于 2019-11-28 11:44:22
问题 I'm trying to encrypt/decrypt a file using XOR. I have the following encryption/decryption routine where every byte is xor'd and the result is being subtracted by the value of the byte that is located at the previous location. The ASM representation is as follows crypt: mov dl, [eax+ecx] ; read byte xor dl, 0C5h ; xor it with oxC5 sub dl, [eax+ecx-1] ; sub the previous byte mov [eax+ecx], dl ; save the new byte dec eax ; decrement pointer test eax, eax jg short crypt ; That is what my

XOR register,register (assembler)

ε祈祈猫儿з 提交于 2019-11-28 07:39:03
问题 From time to time we have to analyze pieces of assembler code (IA32), and more than often i come across an instruction that looks like this: xor ax, ax or with other registers aswell: xor dx, dx , xor al, al , ... What exactly does this do ? (ax xor ax always gives 0 ?) 回答1: It's a common assembler idiom to set a register to 0. xor ax, ax corresponds to ax = ax ^ ax which, as you already notices, is effectively ax = 0 . If I recall correctly the main advantage is that its code-size is smaller

Difference between the AVX instructions vxorpd and vpxor

↘锁芯ラ 提交于 2019-11-28 07:16:16
问题 According to the Intel Intrinsics Guide, vxorpd ymm, ymm, ymm : Compute the bitwise XOR of packed double-precision (64-bit) floating-point elements in a and b, and store the results in dst. vpxor ymm, ymm, ymm : Compute the bitwise XOR of 256 bits (representing integer data) in a and b, and store the result in dst. What is the difference between the two? It appears to me that both instructions would do a bitwise XOR on all 256 bits of the ymm registers. Is there any performance penalty if I

Functional variant of 'oneof' function in Racket

孤街浪徒 提交于 2019-11-28 05:42:51
问题 I have written following function to find if one and only one of 5 variables is true: (define (oneof v w x y z) (or (and v (not w) (not x) (not y) (not z)) (and w (not v) (not x) (not y) (not z)) (and x (not v) (not w) (not y) (not z)) (and y (not v) (not w) (not x) (not z)) (and z (not v) (not w) (not x) (not y)) )) (xor takes only 2 arguments) However, it is very imperative and not functional. Moreover, I want to write a function (oneof N) which will be generic rather than specific for 5

What does bitwise XOR (exclusive OR) mean?

浪尽此生 提交于 2019-11-28 03:03:48
I'm trying to understand the binary operators in C# or in general, in particular ^ - exclusive or . For example: Given an array of positive integers. All numbers occur even number of times except one number which occurs odd number of times. Find the number in O(n) time and constant space. This can be done with ^ as follows: Do bitwise XOR of all the elements. Finally we get the number which has odd occurrences. How does it work? When I do: int res = 2 ^ 3; res = 1; int res = 2 ^ 5; res = 7; int res = 2 ^ 10; res = 8; What's actually happening? What are the other bit magics? Any reference I can

C Programming - XOR Bitwise Operation

回眸只為那壹抹淺笑 提交于 2019-11-28 02:23:56
What operation does the following ‘C’ statement perform? star = star ^ 0b00100100; (A) Toggles bits 2 and 5 of the variable star. (B) Clears all bits except bits 2 and 5 of the variable star. (C) Sets all bits except bits 2 and 5 of the variable star. (D) Multiplies value in the variable star with 0b00100100. I'm still clueless about this. Can someone help me out? XOR operator (also called "logical addition") is defined like this: a b a^b ----------- 0 0 0 0 1 1 1 0 1 1 1 0 So a^0 leaves a intact while a^1 toggles it. For multiple-bit values, the operation is performed bitwise, i.e. between

What is the point of the logical operators in C?

爷,独闯天下 提交于 2019-11-28 01:15:14
问题 I was just wondering if there is an XOR logical operator in C (something like && for AND but for XOR). I know I can split an XOR into ANDs, NOTs and ORs but a simple XOR would be much better. Then it occurred to me that if I use the normal XOR bitwise operator between two conditions, it might just work. And for my tests it did. Consider: int i = 3; int j = 7; int k = 8; Just for the sake of this rather stupid example, if I need k to be either greater than i or greater than j but not both, XOR

sum of xor values of all pairs

我的未来我决定 提交于 2019-11-28 00:09:27
We have an array A (say [1,2,3]) . We need to find the XOR(^)SUM of all pairs of integers in the array. Though this can easily be done in O(n^2) but how can i improve the complexity of the solution ? E.g for the above array , A, the answer would be (1^2)+(1^3)+(2^3) = 6 Thanks. You can separate the calculation to do one bit at a time. For example, look at the rightmost bit of all the numbers in the array. Suppose that a numbers have a rightmost 0-bit, and b numbers have a 1-bit. Then out of the pairs, a*b of them will have 1 in the rightmost bit of the XOR. This is because there are a*b ways

How to find all the subarrays with xor 0?

十年热恋 提交于 2019-11-27 22:38:31
The problem is to find all the subarrays of the given array with xor of all its elements equal to zero. For example, if array contains elements [13,8,5,3,3] , the solution should give the indices of all subarrays like 0-2 , 3-4 , 0-4 , etc. The question is similar to the one asked here The only difference is that I want the indices of all the subarrays that satisfies the equation A0 xor A1 xor...xor An = 0 This is a fairly straightforward extension of the linked question. In Python, # Multivalued map from the XOR of array[:i] to i for all i. prefix_xor_to_stops = {0: [0]} prefix_xor = 0 for j,

Exclusive Or in Regular Expression

こ雲淡風輕ζ 提交于 2019-11-27 20:26:52
Looking for a bit of regex help. I'd like to design an expression that matches a string with " foo " OR " bar ", but not both " foo " AND " bar " If I do something like... /((foo)|(bar))/ It'll match " foobar ". Not what I'm looking for. So, how can I make regex match only when one term or the other is present? Thanks! You can do this with a single regex but I suggest for the sake of readability you do something like... (/foo/ and not /bar/) || (/bar/ and not /foo/) This is what I use: /^(foo|bar){1}$/ See: http://www.regular-expressions.info/quickstart.html under repetition If your regex