• Pada Algoritma pencarian banyak yang bisa kita temukan atau gunakan. Ada Merge Sort, Quick Sort, Bubble Sort, dan...
  • Pada dasarnya algoritma searching banyak kita jumpai. Apalagi hanya untuk mencari nilai minimum dan nilai maximum...
  • Kalian pasti sudah tahu apa itu Deret Fibonacci, ya benar. (Padahal gak jawab). Tetapi pada pembahasan kali ini kita akan membuar program...
  • Metoda Pencarian Biner ( Binary Search) hanya bisa diterapkan jika data array sudah terurut. Pengurutan Array bisa menggunakan jenis sorting ...
  • Salah satu contoh tipe algoritma brute force lainnya adalah linear search (pencarian berurutan), Dikatakan demikian karena algoritma ini menggunakan ...

Friday, May 13, 2011

Kriptografi : Program C++ Enkripsi dan Deskripsi

Cryptography is the science and an art to maintain the confidentiality of messages (data or information) in a way to disguise it into a form that can not be understood. The purpose encryption is that the content of the message can not be understood by unauthorized people.

Some basic terminology of cryptography :
1.      Plainteks (plaintext or cleartext, meaning the text is clear and understandable): messages are kept confidential.
2.      Chiperteks (ciphertext or cryptogram, meaning encrypted text): encoding the message.
3.      Enkripsi (encryption atau enchipering): encoding process of the plaintext to chiperteks.
4.      Dekripsi (decryption atau dechipering): reversal process of the ciphertext to plain text
5.      Algoritma kriptografi (atau chiper):

Example :
plainteks  : uang disimpan di balik buku X
chiperteks: j&kloP(d$gkhtpuBn%6^klp..t@8^

Mathematical notation

For example:
C = chiperteks
P = plaintext
then the encryption function E mapping P  to C  -->  E(P) = C, and
decryption function D maps C  to P   --> D(C) = P 

Caesar Cipher
Caesar Cipher is an algorithm by substituting characters with other characters.

Substitution table:

pi : 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
ci : D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

With each letter of the alphabet to encode an integer as follows: A = 0, B = 1, ..., Z = 25, then mathematically caesar cipher to encrypt the plaintext pi become ci with the rules:

ci = E(pi) = (pi + 3) mod 26

and decryption chiperteks ci  become pi with rules : pi = D(ci) = (ci – 3) mod 26  

To encrypt or description of the program can be made. We are of the friction with the ASCII code of key. In the example rules above, key = 3. In the program we can use the input from the user how many keys.

This function for encryption :

void kriptografi::enkripsi(){
     for(int i=0; i<strlen(plain); i++){
             chiper[i]=(plain[i]+key)%128;
             }
     cout<<endl<<endl;
     }

    
Here's to a description :

void kriptografi::deskripsi(){
     for (int i=0; i<strlen(chiper); i++){
         teks[i]=(chiper[i]-key)%128;
         }
     }

Complete program to be tried can be downloaded here
Readmore

Big Integer : Many Digit Addition with Integer Data Type (Penjumlahan Banyak Digit dengan Tipe Data Integer)

You all know that the numbers are integer data types must be limited to 10 digits only. And what if kitaa want to add a lot of digits. Suppose we have a 30-digit numbers. Surely if we create a program using only integer types aka error results. Therefore, we can use arrays. Each digit aka stored in a single array element. Example :

We take the first number 57575757, the second number 12345678
In the program number will be stored in each array element.

The first number
5
7
5
7
5
7
5
7


The second number
1
2
3
4
5
6
7
8

 

Having obtained such that every sum of digits performed live. But here happened the outcome of the sum is also stored role in every element of the array. As the above example will occur 7 + 8 = 15. Number 15 aka the last element stored in the array. So we must be smart - smart play with the computer. We use modulo to get the number 5. So that is not stored in the memory array 15. The next smaller digit we add 1. Because 10 of 15 had been added in front of him. As usual summation in primary schools.

Based on that logic could be a program that can count up the number of big integers. That is the number of type integer, but has plenty of appropriate digits we want.

Writing can be made ​​like this :
void aritmatika::penjumlahan(){
     for(int i=(digit-1);i>=0;i--){
             jumlah[i]=jumlah[i]+input1[i]+input2[i];
             if (jumlah[i] >9 && i !=0){
                               jumlah[i]=jumlah[i]%10;
                               jumlah[i-1]=jumlah[i-1]+1;
                               }
             }
     }

Easy right opponent? Next let us work. For all the code themselves can be downloaded here
Readmore

Vektor : Program C + + Vector Addition and Multiplication Vector (Program C++ Penjumlahan Vektor dan Perkalian Vektor)

SKALAR AND VEKTOR

Scalar is a quantity sufficient magnitude is expressed alone (not dependent on the way). For example: mass, time, energy and so on.
The vector is a quantity that depends on the direction. For example: speed, force, momentum, etc.

In Cartesian coordinates :
       Vector direction / unit vector is a vector of magnitude 1 and in accordance with a defined direction. For example in Cartesian coordinates: i, j, k, respectively - each state vector in the direction parallel to the x axis, y axis and the axis z.
        So that the vector a can be written :

                                a = ax  i + ay  j

          and the large vector a is :
         
                                a = sqrt( ax +  ay 2 )
Addition operation :
A + B = ?
        + Sign in the summation vector has extended meanings.
         So A + B has a mean vector A may be extended by the vector B.

Vector multiplication by scalar :
Examples of a vector multiplication by a scalar in physics: F = ma, p = mv, etc.
where m: scalar and a, v: vector.
If for example A and B are vectors and k is a scalar then,

                    B = k A

Large vector B is k times while the direction of the vector A vector B is equal to the direction of vector A when k positive and the opposite if k is negative. Example: F = QE, q is the electric charge can be charged positive or negative so that the direction of F depends on the charge sign.

Based on the case, here's created a program to compute the vector addition and multiplication by a scalar vector. To sum ​​as follows :

void vektor::penjumlahan_vektor(const vektor& a, const vektor& b){
     if (a.banyak > b.banyak) banyak = a.banyak;
     else banyak = b.banyak;
     for(int i=0;i<banyak;i++){
             elemen[i] = a.elemen[i] + b.elemen[i];
             }
     }
    
For vector multiplication with skalar be made ​​like this :

void vektor::perkalian_vektor(float k, const vektor& d){
     banyak = d.banyak;
     for(int i=0;i<banyak;i++){
             elemen[i]=k * d.elemen[i];
             }
     }

Complete program can be downloaded here
Readmore

Tutorial Algorithm and Programming ©Template Blogger Green by Dicas Blogger.

To Up