tricky binary subtraction - math

So I was practicing my binary subtraction. It's been a long while since my first exam and I decided to create my own tricky binary subtraction and I came up with this one:
1100
-1101
Of course the "borrowing trick" does not work for this problem at least I could not get it to work. Is my only choice to flip the bits of the second binary number(the bottom one) and then add a one basically doing 2's complement so 1101 becomes 0011. Then add the primary binary number(1100) with the 2's complement representation(0011) which means it would look like this:
1100 (-4) assume 2's complement
+ 0011 (3) assume 2's complement
sum:1111 (-1) assume 2's complement
I just need confirmation on this problem since its been a long time since I did binary subtraction.

1100
-1101
0 - 1 = 1 (borrow 1)
1100
-1101
1
=====
1
0 - 0 - 1 = 1 (borrow 1)
1100
-1101
11
=====
11
1 - 1 - 1 = 1 (borrow 1)
1100
-1101
111
=====
111
1 - 1 - 1 = 1 (borrow 1)
1100
-1101
1111
=====
1111
The result is 1111 with 1 borrowed. In terms of unsigned arithmetic, this means that either the result underflowed or you need to borrow from the next significant digit. (In terms of signed arithmetic there is no overflow as you have also borrowed the second bit and the calculation corresponds to -4 - -3 = -1.)

Related

Stream cipher LFSR Known-Plaintext

I am currently learning cryptography,
I got different tasks. The current one features stream ciphers based on LFSR which can be solved with the Gaussian algorithm.
The cipher is: 0001 0010 01101101
I know that the first 8 bits of plaintext are all 1.
The length of n is 4.
So if I XOR them I get:
11101101
But now I am stuck and don't know how to translate it into a correct matrix.
1 1 1 0 | ?
1 1 0 1 | ?
1 0 1 1 | ?
0 1 1 0 | ?
Is this the correct way or do there only need to be 3 variables in front of the line? And where do I get the solution of the question marks from?
I hope someone can help me understanding cryptography. Thanks.

In Unix what does the ^ do when placed in a math expression

I have been searching for the answer to this and was unable to find an exact answer help will be much appreciated.
echo $[ 2 ^ 2 ]
returns value 0
echo $[ 2 ^ 3 ]
returns 1
echo $[ 2 ^ 4 ]
returns 6
My question is what math operation is taking place when using the ^ in this context?
I expected to see a power of function. Would really appreciate any clarification, thanks in advance.
It's a bitwise XOR operation.
It compares the bits for the two numbers, and if for a given position, one of the bits is 1, the resulting bit will also be set to 1. In all other cases, the resulting bit will be 0.
So, for your examples:
2 010
2 010
--------
0 000
2 010
3 011
--------
1 001
2 010
4 100
--------
6 110
I would say, your commands are doing a bit-xor with the numbers.

What is the correct name of this error correction method (it is similar to Hamming Code)

What is the correct name of this error correction method?
It is quite similar to Hamming Code, but much more simple. I also cannot find it in the literature any more. The only internet sources, I'm now able to find, which describes the method, are this:
http://www.mathcs.emory.edu/~cheung/Courses/455/Syllabus/2-physical/errors-Hamming.html
And the german-language Wikipedia.
http://de.wikipedia.org/w/index.php?title=Fehlerkorrekturverfahren
In the Wikipedia article, the method is called Hamming-ECC method. But I'm not 100% sure, this is correct.
Here is an example, which describes the way the method works.
Payload: 10011010
Step 1: Determine parity bit positions. Bits, which are powers of 2 (1, 2, 4, 8, 16, etc.) are parity bits:
Position: 1 2 3 4 5 6 7 8 9 10 11 12
Data to be transmitted: ? ? 1 ? 0 0 1 ? 1 0 1 0
Step 2: Calculate parity bit values. Each bit position in the transmission is assigned to a position number. In this example, the position number is a 4-digit number, because we have 4 parity bits. Calculate XOR of the values of those positions (in 4-digit format), where the payload is a 1 bit in the transmission:
0011 Position 3
0111 Position 7
1001 Position 9
XOR 1011 Position 11
--------------------
0110 = parity bit values
Step 3: Insert parity bit values into the transmission:
Position: 1 2 3 4 5 6 7 8 9 10 11 12
Data to be transmitted: 0 1 1 1 0 0 1 0 1 0 1 0
Is is quite simple to verify, if a received message was transmitted correctly and single-bit errors can be corrected. Here is an example. The receiver calulates XOR of the calculated and received payload bits where the value is a 1 bit. Is the result is 0, there the transmission is error-free. Otherwise the result contains the position of the bit with the wrong value.
Received message: 0001101100101101
Position: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Received data: 0 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1
Parity bits: X X X X X
00101 Position 5
00111 Position 7
01011 Position 11
01101 Position 13
XOR 01110 Position 14
--------------------
01010 Parity bits calculated
XOR 00111 Parity bits received
--------------------
01101 => Bit 13 ist defective!
I hope, anybody here knows the correct name of the method.
Thanks for any help.
This looks like a complicated implementation of the Hamming(15,11) encoding & decoding algorithm.
Interleaving the parity bits with the information bits does not change the behaviour (or performance) of the code. Your description only uses 8 information bits, where the Hamming(15,11) corrects all single bit errors even with 11 information bits being transmitted.
Your description does not explain how the transmitted 12-bit message gets extended to a 16-bit message on the receive side.

Possible combinations of -1 0 & +1

Surveys offered to customers to provide feedback on the consultant that they dealt with. Customer gives a score of 1 to 10.
Scores are grouped as:
1-6
7-8
9-10
If score <= 6 then this = detractor which constitutes a negative one: -1
7-8 = 0 (neutral)
Scores of 9 and 10 = +1.
So although there are 10 possible responses by the customer (1:10) this ends up being either -1, 0 or +1. So only 3 possible outcomes: -1,0,+1.
Say 10 surveys are done it may looks like this:
-1,+1,0,0,+1,+1,-1,+1,0,0 = +2
Then this +2 is divided by survey counts and multiplied by 100. So 2/10 = 0.2 *
100 = 20.
Now to the tricky part.
I want to figure out the possible sum totals (like the +2 calc'd 5 lines up). Best explained with a simple example:
1 Survey = either a -1, 0 or +1 so 3 possible outcomes.
2 surveys possibilities
-1,-1 equals -2
-1,0 equals -1
-1,+1 equals 0
0,0 equals 0
0,1 equals +1
+1,+1 equals 2
So although there are 6 possible combinations this is not what I am after. The order and individual totals are not what I am after it's just the possible sum of n surveys. In this case there's only one -2, -1, +1 and +2. That's 4. But there are 2 combinations that sum to zero so this is only 1 possible outcome from a sum perspective. So in this case given 2 surveys there is only 5 possible summed amounts.
I can do these simple one's by hand but what if there were 20 surveys? That'd be silly obviously. I would like to know if there is a way that in R I can use an algorithm to solve this for as many surveys that I need to examine this for.
As written in the comments above:
Obviously, the sum can range from -n to +n where n is the number of surveys, a total of 2 n + 1 possible sums. – Gassa 11 mins ago
This is a way you can reach this conclusion:
Start to create the full logic table of the outcome
+1 +1 2
+1 0 1
+1 -1 0
0 +1 1
0 0 0
0 -1 -1
-1 +1 0
-1 0 -1
-1 -1 -2
So with 2 surveys you have to 2^3 possible outcomes, with a few duplicates boiling down to the unique set 2,1,0,-1,-2
combine this with the next survey
+1 +2 3
+1 +1 2
+1 0 1
[..]
-1 0 -1
-1 -1 -2
-1 -2 -3
For every new survey you add you will end up with
+1 +(N-1) N
+1 +(N-2) N-1
[..]
-1 -(N-2) -(N-1)
-1 -(N-1) -N
The conclusion would be the max and min outcome will be +-N where N is the number of surveys given.
Maybe this article on wikipedia about 3-way logic is what you are looking for:
http://en.wikipedia.org/wiki/Three-valued_logic

"Calculations" of 6-digit octals in 8's complement, in layman's terms?

How does one find the postive/negative range of a 6-digit octal in 8's complement? From what I understand, it's simply half - 1:
000001 - 377777 positives, 400000 - 77777 negatives
Would 377777 be the highest positive, and 777777 the highest negative number?
If that is correct, it seems to me that 377777 and 777777 are complements of each other. However, from what I've read, to find the complement, subtract the number from the base. Doing that, 377777 would equal:
7 - 3 = 4
7 - 7 = 0
7 - 7 = 0
7 - 7 = 0
7 - 7 = 0
7 - 7 = 0
= 400000
This shows 400000 is the complement of 37777 (which appears inverse to me).

Resources