برمجة شفرة فجنير Vigenere Cipher :

الفرنسي بليز دي فجنير
العالم الفرنسي بليز دي فجنير

اخترعت هذه الشفرة من قبل العالم الفرنسي بليز دي فجنير . تعتبر هذه الشفرة من اقوي الشفرات التقليدية التى اخترعت من اقوى التشفير التقليدى . حيث لم يتم كسر هذه الشفرة منذ عشرات السنين . اعتقدوا انها غير قابلة للكسر حتى جاء هذا العالم وقام بكسرها العالم فريدريك كاسكي وهو ضابط برتبة رائد في المشاة البحرية الالمانية . استخدمت هذه الطريقة في الحرب العالمية الاولى و الثانية.

طريقة التشفير Vigenere Cipher:


تفترض هذه الطريقة وجود مصفوفة ثنائية ابعادها 26 * 26 و ان تشفير الكلمة الواضحة plain text يكون من تقابل الصفوف مع الاعمدة للحرف المختار من النص الواضح والحرف المختار من المفتاح الانسيابي . لاحظ الصورة ادناه :


فلنعتبر الرسالة:THECRAZYPROGRAMMER
والمفتاح:HELLO

هكذا يكون لدينا مفتاح جديد يتكرر مع المفتاح المعطى مع المسافات والعدد فى الصفوف حتى يعطى لنا مفتاح تم توليده بهذه الشفرة:
المفتاح الجديد الذي تم توليده: HELLOHELLOHELLOHEL

برنامج Vigenere Cipher بلغة C:

الكود:
#include<stdio.h>
#include<string.h>
 
int main(){
    char msg[] = "THECRAZYPROGRAMMER";
    char key[] = "HELLO";
    int msgLen = strlen(msg), keyLen = strlen(key), i, j;
 
    char newKey[msgLen], encryptedMsg[msgLen], decryptedMsg[msgLen];
 
    //generating new key
    for(i = 0, j = 0; i < msgLen; ++i, ++j){
        if(j == keyLen)
            j = 0;
 
        newKey[i] = key[j];
    }
 
    newKey[i] = '\0';
 
    //encryption
    for(i = 0; i < msgLen; ++i)
        encryptedMsg[i] = ((msg[i] + newKey[i]) % 26) + 'A';
 
    encryptedMsg[i] = '\0';
 
    //decryption
    for(i = 0; i < msgLen; ++i)
        decryptedMsg[i] = (((encryptedMsg[i] - newKey[i]) + 26) % 26) + 'A';
 
    decryptedMsg[i] = '\0';
 
    printf("Original Message: %s", msg);
    printf("\nKey: %s", key);
    printf("\nNew Generated Key: %s", newKey);
    printf("\nEncrypted Message: %s", encryptedMsg);
    printf("\nDecrypted Message: %s", decryptedMsg);
 
return 0;
}
 المخرجات:
Original Message: THECRAZYPROGRAMMER
Key: HELLO
New Generated Key: HELLOHELLOHELLOHEL
Encrypted Message: ALPNFHDJAFVKCLATIC
Decrypted Message: THECRAZYPROGRAMMER


برنامج Vigenere Cipher بلعة ++C:


#include<iostream>
#include<string.h>
 
using namespace std;
 
int main(){
    char msg[] = "THECRAZYPROGRAMMER";
    char key[] = "HELLO";
    int msgLen = strlen(msg), keyLen = strlen(key), i, j;
 
    char newKey[msgLen], encryptedMsg[msgLen], decryptedMsg[msgLen];
 
    //generating new key
    for(i = 0, j = 0; i < msgLen; ++i, ++j){
        if(j == keyLen)
            j = 0;
 
        newKey[i] = key[j];
    }
 
    newKey[i] = '\0';
 
    //encryption
    for(i = 0; i < msgLen; ++i)
        encryptedMsg[i] = ((msg[i] + newKey[i]) % 26) + 'A';
 
    encryptedMsg[i] = '\0';
 
    //decryption
    for(i = 0; i < msgLen; ++i)
        decryptedMsg[i] = (((encryptedMsg[i] - newKey[i]) + 26) % 26) + 'A';
 
    decryptedMsg[i] = '\0';
 
    cout<<"Original Message: "<<msg;
    cout<<"\nKey: "<<key;
    cout<<"\nNew Generated Key: "<<newKey;
    cout<<"\nEncrypted Message: "<<encryptedMsg;
    cout<<"\nDecrypted Message: "<<decryptedMsg;
 
return 0;
}

اذا اردت سؤال اى شئ نحن هنا واذا يوجد اى اخطاء فى الكود يرجي ابلاغى 

جديد قسم : برمجة

إرسال تعليق