xor

XOR Binary in PHP

泄露秘密 提交于 2019-12-02 13:04:31
I want to XOR the binary but the result is still wrong xor xor example script: function _xor($text,$key){ for($i=0; $i<strlen($text); $i++){ for($j=0; $j<strlen($key);$j++){ $text[$i] = $text[$i]^$key[$j]; } } return $text; } and this is the result : 10011110 should result xor between 01100001 01100010 -------- 00000011 please give me the right answer function _xor($text,$key){ for($i=0; $i<strlen($text); $i++){ $text[$i] = intval($text[$i])^intval($key[$i]); } return $text; } echo _xor('01100001','01100010'); Before you use ^ , you should first convert string to int There not need use two

Why doesn't my simple XOR encryption program translate the characters right, and why does it add more characters at the end?

别等时光非礼了梦想. 提交于 2019-12-02 11:17:11
I'm making a XOR based en/decryptor, that works like this. You have a plaintext character, for example 3, and a user key, for example 5. Written in bits: 3 = 00000011 5 = 00000101 Now if we do XOR operation, we get 6: 6 = 00000110 This can be reversed by saying 6 XOR 5, which is 3. So I have made this program. But it's really buggy, it doesn't translate the text right, and it adds a lot of characters in the end of the file, depending which key you are using. using namespace std; int main(int argc, char *argv[]) { char buffer[5001]; ifstream fin("a.txt", ifstream::in); ofstream fout("b.txt");

Weird XOR swap behavior while zeroing out data

狂风中的少年 提交于 2019-12-02 00:34:00
问题 Thanks Doug. Here's the fix: void swap(int& a, int& b) { if (&a == &b) // added this check to ensure the same address is not passed in return; a ^= b; b ^= a; a ^= b; } I am implementing quicksort for fun in C++, and I am using integers for dummy data. I had been using the XOR swapping algorithm to swap two values in place, but I noticed my sort was screwing up. I changed my swapping algorithm and it worked. I added some debugging statements, and found that the XOR swap was doing something

Weird XOR swap behavior while zeroing out data

好久不见. 提交于 2019-12-01 20:15:34
Thanks Doug. Here's the fix: void swap(int& a, int& b) { if (&a == &b) // added this check to ensure the same address is not passed in return; a ^= b; b ^= a; a ^= b; } I am implementing quicksort for fun in C++, and I am using integers for dummy data. I had been using the XOR swapping algorithm to swap two values in place, but I noticed my sort was screwing up. I changed my swapping algorithm and it worked. I added some debugging statements, and found that the XOR swap was doing something weird. I printed the data before and after I swapped it, and this is what it printed: ... swapping -5, -3

Multiple assignment on one line not working as expected

点点圈 提交于 2019-12-01 14:58:52
I'm trying to swap two int s - x and y in the example, and do it in one line without a library function. So I started with this: int x = 4; int y = 3; System.out.println(x); System.out.println(y); x ^= y; System.out.println(x); System.out.println(y); y ^= x; System.out.println(x); System.out.println(y); x ^= y; System.out.println(x); System.out.println(y); The output was 4, 3, 7, 3, 7, 4, 3, 4 as expected. All good so far. Next up was this: int x = 4; int y = 3; System.out.println(x); System.out.println(y); y ^= (x ^= y); System.out.println(x); System.out.println(y); x ^= y; System.out.println

Multiple assignment on one line not working as expected

会有一股神秘感。 提交于 2019-12-01 13:46:14
问题 I'm trying to swap two int s - x and y in the example, and do it in one line without a library function. So I started with this: int x = 4; int y = 3; System.out.println(x); System.out.println(y); x ^= y; System.out.println(x); System.out.println(y); y ^= x; System.out.println(x); System.out.println(y); x ^= y; System.out.println(x); System.out.println(y); The output was 4, 3, 7, 3, 7, 4, 3, 4 as expected. All good so far. Next up was this: int x = 4; int y = 3; System.out.println(x); System

Implementing OR,AND using XOR

ぐ巨炮叔叔 提交于 2019-12-01 12:57:37
问题 I want to know that if I can implement or,and functions using only xor . I think It is impossible but I need to prove that. Any ideas? Thanks in advance. 回答1: You cannot implement OR or AND gate only by using XOR because it is not a universal gate. Also the XOR function can't tell the difference between '1,1' and '0,0' at it's inputs. Inverting the inputs/output in whatever combination makes a new gate with an XOR or XNOR function. Here is an argument against XOR and XNOR as universal gates.

How can I use SIMD to accelerate XOR two blocks of memory?

◇◆丶佛笑我妖孽 提交于 2019-12-01 06:00:50
I want to XOR two blocks of memory as quickly as possible, How can I use SIMD to accelerate it? My original code is below: void region_xor_w64( unsigned char *r1, /* Region 1 */ unsigned char *r2, /* Region 2 */ int nbytes) /* Number of bytes in region */ { uint64_t *l1; uint64_t *l2; uint64_t *ltop; unsigned char *ctop; ctop = r1 + nbytes; ltop = (uint64_t *) ctop; l1 = (uint64_t *) r1; l2 = (uint64_t *) r2; while (l1 < ltop) { *l2 = ((*l1) ^ (*l2)); l1++; l2++; } } I wrote one myself, but little speed increased. void region_xor_sse( unsigned char* dst, unsigned char* src, int block_size){

How to solve systems of XOR equations?

牧云@^-^@ 提交于 2019-12-01 05:56:47
I have to solve a system that consists of 32 xor equations, each involving 15 of 32 variables. One would look like this: i[0] = p[0] ^ p[4] ^ p[5] ^ p[10] ^ p[11] ^ p[20] ^ p[21] ^ p[22] ^ p[23] ^ p[25] ^ p[26] ^ p[27] ^ p[28] ^ p[30] ^ p[31] i[n] and p[n] being 16 bit integers. So as I understand I would end up with a 32x32 matrix (containing only 1s and 0s) and a 32 result vector. Apparently Gaussian elimination is what I need but I can't wrap my mind around the problem, could someone give me some insight on how to solve such a problem? Yes, you can use gaussian elimination to solve this.