Skip to main content
36 votes

Can I encrypt a message by swapping bits in the text?

First problem is you're not specifying at all how many swaps you need to do for a given message length, other than saying it's "several." For an $n$-bit messsage there are $n!$ ways of rearranging its ...
Luis Casillas's user avatar
24 votes
Accepted

Why is a known-plaintext attack considered a complete break?

if a cipher has a known-plaintext attack, then it is considered completely broken. Yes, pretty much... [Paraphrased] But can't we come up with a case where this isn't true, such as a One Time Pad? ...
poncho's user avatar
  • 148k
22 votes
Accepted

What is wrong with XOR encryption with secure PRNG?

The bytes that you XOR with the message to get the ciphertext are called the key stream. It is secure to create a key stream using a CSPRNG yes, a cryptographically secure pseudo-random number ...
Maarten Bodewes's user avatar
  • 93.2k
21 votes

why XOR is recommended/Used in every paper I read for encryption and decryption stream cipher?

Why can't I use other opeartions such as NAND, AND, OR Because it needs to be invertible. For example, if you use NAND, then if the bit from the key generator is a 0, then the output of the NAND will ...
poncho's user avatar
  • 148k
17 votes

Why is a known-plaintext attack considered a complete break?

If the user changes the key for every message sent, then what use is a known-plaintext attack? Stop right there. This is not what we are trying to prove when conducting a known-plaintext attack. A ...
mikeazo's user avatar
  • 38.7k
17 votes
Accepted

What's wrong with XOR encryption with hash and an iterated salt

Assuming that: the functions $F_k(s) = {\rm hash}(k + s)$ form a pseudorandom function family (PRF) indexed by the key $k$, and each key is only used to encrypt one message, then this construction ...
Ilmari Karonen's user avatar
17 votes
Accepted

XOR a set of random numbers

Assuming that $b = 2^k-1$ for some positive integer $k$, XORing two (or more) numbers in the range $[0,b]$ will indeed yield a number in the same range. If the numbers are random, uniformly ...
Ilmari Karonen's user avatar
16 votes

What is wrong with XOR encryption with secure PRNG?

Yes, you can; it's called a stream cipher. It can be viewed as an approximation of a one-time pad, where you don't have enough entropy available to generate an OTP key (which must be the same length ...
dan04's user avatar
  • 279
13 votes
Accepted

Extracting randomness from highly-biased RNG

If the source as 3 entropy bits per 1024 source bits, constructing a 128-bit seed requires $\lceil128\cdot 1024/3\rceil=43691$ source bits at least. The "XOR 350 bits with jump 128 bits" translates ...
fgrieu's user avatar
  • 142k
12 votes

Why is XOR preferred over XNOR?

$\operatorname{XOR}$ is similar to addition when working on Booleans; by contrast, $\operatorname{XNOR}$ is not a group law if we want to use $0$ as neutral. Economy for extension: we can build a 3-...
fgrieu's user avatar
  • 142k
11 votes

What's wrong with XOR encryption with hash and an iterated salt

There are several possible attacks. Off the top of my head, if an attacker manages to fool you into encrypting a very long message consisting of zeros (00.......00000), then the resulting ciphertext ...
cygnusv's user avatar
  • 5,002
11 votes
Accepted

What are the performance reasons behind "xor-a-rotated-sum" instead of "add-a-rotated-xor" in Salsa20?

Three-operand means two source registers and one destination register. Most x86 instructions reuse one of the source registers as the destination, so you must use an extra MOV instruction to copy one ...
benrg's user avatar
  • 776
10 votes

How to XOR two hexa numbers by hand fast

If you are lucky, the definition of "simple calculator" may include all non-graphic calculators. In that case, you can use a Casio FX-115ES Plus, which includes hexadecimal and octal base modes, and ...
Richie Frame's user avatar
  • 13.1k
10 votes
Accepted

Salsa20 Implementation: Sum of 2 Words with Carries Suppressed

The sum of two words with carries suppressed is just a convoluted way of saying XOR. You don't need to implement any kind of complicated summation operation. Just perform a bitwise-exclusive OR. I ...
forest's user avatar
  • 15.3k
10 votes
Accepted

What are linear and non-linear elements in cryptography?

A mathematical function $f$ is linear if it is of the form $f(t) = c + g(t)$ where $c$ is a constant and $g$ has the property that $g(a + b) = g(a) + g(b)$. (Strictly speaking, in math one usually ...
Squeamish Ossifrage's user avatar
10 votes
Accepted

Does XOR'ing a random number with its inverse reduce its security if the result is a palindrome?

The xor of two random strings is a random string, so you're basically generating a 128-bit random string from a 256-bit random string. Yes, it reduces security compared to a pure 256-bit random ...
Conrado's user avatar
  • 6,484
10 votes

Nexor, an encryption algorithm that promises unlimited key sizes: Is it safe?

Looking very briefly at the source, it's just using the output of /dev/urandom to generate keys, then using that as a (poor) One-Time Pad. /dev/urandom is just a ChaCha20-based RNG with some decent ...
SAI Peregrinus's user avatar
9 votes

How secure is XOR-CBC?

Completely insecure. If you just replace the encryption with XOR with the key, then the first ciphertext block is just $c_1=m_1 \oplus k$. The second block would be $c_2=m_2 \oplus c_1 \oplus k = ...
tylo's user avatar
  • 12.7k
8 votes
Accepted

AES in Counter mode for 64 bit input

The idea of a counter stream mode of AES is to generate an random stream of bits by chunk of 128 bits but you are not forced to use all the 128 bits of it. To encrypt the process is the following, ...
Biv's user avatar
  • 10k
8 votes
Accepted

Can I use PBKDF2 as a stream cipher?

TL;DR: Yes, you can use PBKDF2 as a stream cipher. However, you should not use it for that and for its intended purpose (i.e. password-based key derivation) at the same time. Instead, if you need to ...
Ilmari Karonen's user avatar
8 votes

Multi-Embedded Xor for Perfect OTP

What if we XOR it multiple times with different keys, like this: $Cyphertext=((((((Plaintext⊕K1)⊕K2)⊕K3)⊕K4)⊕K5)....⊕Kn$ This is equivalent to XOR with a single key $K$ where $K = K_1 \oplus K_2 \...
Ella Rose's user avatar
  • 19.7k
8 votes
Accepted

Is a one-time pad secure if the encryption method is not?

OTP requires a completely random key. That's next to impossible, and human genes are certainly not completely random. This is why OTP's are mainly theoretical constructs. XOR is the normal way of ...
Maarten Bodewes's user avatar
  • 93.2k
8 votes
Accepted

How to decrypt two images encrypted using XOR with the same key?

PNG is a compressed image format. This means that, unlike with uncompressed formats like BMP or netpbm, the bytes stored on disk in the PNG file do not correspond directly to the bytes of actual ...
Ilmari Karonen's user avatar
8 votes

why XOR is recommended/Used in every paper I read for encryption and decryption stream cipher?

Edit: For any additive group operation, including addition modulo $k$ if the added keystream symbols $z_t$ are uniformly distributed, which means $$ Pr(z_t=a)=1/k, \quad \forall a \in \{0,\ldots, k-1\...
kodlu's user avatar
  • 22.7k
7 votes

MAC security using encryption

TL;DR: It is a bad one. Proof: Consider a message $m$ such that $m = M_1 || M_2 || \ldots || M_n$ where $||$ is the concatenation and $M_{1..n}$ are of the same size (typically here 128 bits) and ...
Biv's user avatar
  • 10k
7 votes

XOR and key reuse

You've constructed a (somewhat artificial) special case where what you call the "plaintexts" also meet the requisites that one-time pad keys are supposed to meet: Secret Chosen uniformly at random ...
Luis Casillas's user avatar
7 votes

ChaCha20: is this a potentially safe way of using nonce derived from private key if the key/nonce pair is never reused, for a given plaintext?

I realize in ChaCha20 the nonce should be random and unique each time… Nope! For the ChaCha stream cipher, it is not safe to choose the nonce at random. At 64 bits long, the ChaCha nonce is too ...
Squeamish Ossifrage's user avatar
7 votes
Accepted

Why is the second XOR operation in OCB mode necessary?

I am wondering, why the second XOR operation is necessary. If it is omitted, then an arbitrary permutation of the ciphertext blocks would not modify the tag, and hence any such modification would ...
poncho's user avatar
  • 148k
7 votes

why XOR is recommended/Used in every paper I read for encryption and decryption stream cipher?

The first reason obviously is that XOR is reversible. AND and NAND are not reversible. But the important reason is found by looking at the truth table for XOR Let $x$ be the plain text bit & let ...
user93353's user avatar
  • 2,295
6 votes
Accepted

One-time pad XOR question

You do not need to use XOR as the combining operation. You can use modular addition as the encryption function and modular subtraction as the decryption function and it will remain information ...
Ella Rose's user avatar
  • 19.7k

Only top scored, non community-wiki answers of a minimum length are eligible