ভিজিনার সাইফার (Vigenere Cipher) একটি পলিআলফাবেটিক সাবস্টিটিউশন মেথড (polyalphabetic substitution method) যা অ্যালফাবেটিক টেক্সট এনক্রিপ্ট করতে ব্যবহৃত হয়।
এনক্রিপশন এবং ডিক্রিপশনের জন্য ভিজিনার সাইফার টেবিল (Vigenere Cipher Table) ব্যবহার করা হয় যেখানে A থেকে Z অক্ষরগুলো ২৬ রোতে লেখা থাকে।

এনক্রিপশন (Encryption)
Key: WELCOME
Message: Thisistutorialspoint
দেওয়া কীকে রিপিট করে এর দৈর্ঘ্য মেসেজের দৈর্ঘ্যের সমান করতে হয়।
এনক্রিপশনের জন্য মেসেজ এবং কীয়ের প্রথম অক্ষর নিন (T এবং W)। ভিজিনার টেবিলে T রো এবং W কলামের ছেদবিন্দুতে থাকা অক্ষর নিন (P)।
মেসেজ টেক্সটের বাকি সব অক্ষরের জন্য একই প্রসেস दुहरান।
শেষে এনক্রিপ্টেড মেসেজ:
Encrypted Message: PLTUWEXQXZTWMPOTZKBF
সাইফার টেক্স্ট নিচের সমীকরণ দিয়ে জেনারেট করা যায়:
Ei = (Pi + Ki) mod 26 এখানে P = প্লেইন টেক্সট, K = কী
ডিক্রিপশন (Decryption)
Key: WELCOME
Encrypted Message: PLTUWEXQXZTWMPOTZKBF
জেনারেটেড কী এবং এনক্রিপ্টেড মেসেজের প্রথম অক্ষর (P এবং W) নিন। টেবিলে কলাম W-তে P খুঁজুন, করেসপন্ডিং রোই হবে মূল মেসেজের প্রথম অক্ষর (T)।
এনক্রিপ্টেড মেসেজের সব অক্ষরের জন্য একই প্রসেস করুন।
Original Message: Thisistutorialspoint
এলজেব্রাইক ফর্মে:
Pi = (Ei - Ki + 26) mod 26
এলগরিদম
Begin
Function encryption(string t)
for i = 0, j = 0 to t.length() - 1
char c = t[i]
if (c >= 'a' and c <= 'z') c = c + 'A' - 'a'
else if (c < 'A' or c > 'Z') continue
output = output + (c + k[j]) % 26 + 'A'
j = (j + 1) % k.length()
return output
End
Begin
Function decryption(string t)
for i = 0, j = 0 to t.length() - 1
char c = t[i]
if (c >= 'a' and c <= 'z') c = c + 'A' - 'a'
else if (c < 'A' or c > 'Z') continue
output = output + (c - k[j] + 26) % 26 + 'A'
j = (j + 1) % k.length()
return output
End
উদাহরণ
#include <iostream>
#include <string>
using namespace std;
class Vig {
public:
string k;
Vig(string k) {
for (int i = 0; i < k.size(); ++i) {
if (k[i] >= 'A' && k[i] <= 'Z')
this->k += k[i];
else if (k[i] >= 'a' && k[i] <= 'z')
this->k += k[i] + 'A' - 'a';
}
}
string encryption(string t) {
string output;
for (int i = 0, j = 0; i < t.length(); ++i) {
char c = t[i];
if (c >= 'a' && c <= 'z') c += 'A' - 'a';
else if (c < 'A' || c > 'Z') continue;
output += (c + k[j] - 2 * 'A') % 26 + 'A';
j = (j + 1) % k.length();
}
return output;
}
string decryption(string t) {
string output;
for (int i = 0, j = 0; i < t.length(); ++i) {
char c = t[i];
if (c >= 'a' && c <= 'z') c += 'A' - 'a';
else if (c < 'A' || c > 'Z') continue;
output += (c - k[j] + 26) % 26 + 'A';
j = (j + 1) % k.length();
}
return output;
}
};
int main() {
Vig v("WELCOME");
string ori = "Thisistutorialspoint";
string encrypt = v.encryption(ori);
string decrypt = v.decryption(encrypt);
cout << "Original Message: " << ori << endl;
cout << "Encrypted Message: " << encrypt << endl;
cout << "Decrypted Message: " << decrypt << endl;
}
আউটপুট
Original Message: Thisistutorialspoint Encrypted Message: PLTUWEXQXZTWMPOTZKBF Decrypted Message: THISISTUTORIALSPOINT