Rabu, 29 Mei 2013 0 komentar

Number & Letter Randomizing Algorithm


People actually spend a lot of time on good ways to pick pseudo-random numbers.  They try a bunch of different complicated formulas, and try to make sure that patterns don’t pop up.  But we can build a simple one pretty easily to pick pseudo-random numbers from 1 to 10. 
 
random i = 7 * i mod 11  
Since it’s a function, it needs to have an input.  It then multiplies that input by 7, and then finds the remainder when dividing by 11.  We’ll give it the previous number it picked as input, and it will give us back the next one.  Suppose we start at 1.  Then we get the following:
 
random  1 ->  7
random  7 ->  5
random  5 ->  2
random  2 ->  3
random  3 -> 10
random 10 ->  4
random  4 ->  6
random  6 ->  9
random  9 ->  8
random  8 ->  1
 
Since the answer is always a reminder when dividing by 11, it’ll be somewhere between 0 and 10.  But it should be pretty easy to convince ourselves that if the number we give as input is between 1 and 10, then 0 isn’t a possibile answer: if it were, then we’d have found two numbers, both less than 11, that multiply together to give us a multiple of 11.  That’s impossible because…. 11 is prime.  So we’re guaranteed that this process picks numbers between 1 and 10.  It seems to pick them in a non-obvious order with no really obvious patterns, so that’s good.  We appear to have at least a good start on generating random numbers. Notice a couple things:
  • We had to pick somewhere to start.  In this case, we started out by giving an input of 1.  That’s called the seed.  If you use the same seed, you’ll always get the exact same numbers back!  Why?  Because it’s really just a complicated math problem, so if you do the same calculation with the same numbers, you’ll get the same result.
  • To get the next number, we have to remember something (in our case, the last answer) from the previous time.  That’s called the state.  The state is important, because it’s what makes the process give you different answers each time!  If you didn’t remember something from the last time around, then you’d again be doing the same math problem with the same numbers, so you’d get the same answer.
The Algorithm Method for randoming words is : First - Last Method

For Letter :
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
Example :
SECURE
become 
HVXFIV
Rabu, 08 Mei 2013 2 komentar

Permutation-Based Cryptography



The translation of text from clear form to an encrypted form and back is a common problem in computing.  One simple technique for encrypting text is based on the mathematical notion of a permutation.  A permutation of the integers 0 through N-1 is simply a one-to one function whose domain and range are both the set of integers {0, 1, 2, . . . , N-1}.  In other words, a permutation transforms each integer in the set {0, 1, 2, . . . , N-1} into another integer in the same set, with no two integers being transformed into the same result.  For example, here is a permutation of {0, 1, 2, 3, 4}.


This permutation can be used to encrypt a sequence of five characters by moving each character from its original position to the position defined by the permutation.  For example, the sequence "APPLE" would be translated into the string "PLEAP":

Note that we number positions starting at zero just as in C++ arrays — that’s a hint of things to come.  What about decrypting the text above?  Well, each permutation has an inverse, another permutation that does the exact opposite of the original permutation.  For the permutation given above, the inverse permutation is:


Apply the inverse permutation to the scrambled sequence "PLEAP"; you should get back the original sequence "APPLE".  That’s the key point about encryption/decryption using a permutation, apply the permutation, and then apply its inverse, and you get back where you started.

Data Encryption Standard (DES)
DES is the archetypal block cipher — an algorithm that takes a fixed-length string of plaintext bits and transforms it through a series of complicated operations into another ciphertext bitstring of the same length. In the case of DES, the block size is 64 bits. DES also uses a key to customize the transformation, so that decryption can supposedly only be performed by those who know the particular key used to encrypt. The key ostensibly consists of 64 bits; however, only 56 of these are actually used by the algorithm. Eight bits are used solely for checking parity, and are thereafter discarded. Hence the effective key length is 56 bits, and it is always quoted as such.The key is nominally stored or transmitted as 8 bytes, each with odd parity. According to ANSI X3.92-1981, section 3.5: One bit in each 8-bit byte of the KEY may be utilized for error detection in key generation, distribution, and storage. Bits 8, 16,..., 64 are for use in ensuring that each byte is of odd parity.

 
;