Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SaugumasPirmasPD.DbContextApp;
- using SaugumasPirmasPD.Model;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace SaugumasPirmasPD
- {
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- string keyword = "AYUSH";
- public string generateKey(string str, string key)
- {
- int x = str.Length;
- for (int i = 0; ; i++)
- {
- if (x == i)
- i = 0;
- if (key.Length == str.Length)
- break;
- key += (key[i]);
- }
- return key;
- }
- static string cipherText(string str, string key)
- {
- string cipher_text = "";
- for (int i = 0; i < str.Length; i++)
- {
- int x = (str[i] + key[i]) % 26;
- x += 'A';
- cipher_text += (char)(x);
- }
- return cipher_text;
- }
- static String originalText(String cipher_text, String key)
- {
- String orig_text = "";
- for (int i = 0; i < cipher_text.Length &&
- i < key.Length; i++)
- {
- // converting in range 0-25
- int x = (cipher_text[i] -
- key[i] + 26) % 26;
- // convert into alphabets(ASCII)
- x += 'A';
- orig_text += (char)(x);
- }
- return orig_text;
- }
- private void Crypt_Click(object sender, RoutedEventArgs e)
- {
- string str = Pass.Text;
- string str1=str.ToUpper();
- string key = generateKey(str1, keyword);
- string smth = cipherText(str1, key);
- using (var db = new AppDbContext())
- {
- var user = new User { Name = Name.Text, CipherPassword = smth, OriginalPassword= key };
- db.User.Add(user);
- db.SaveChanges();
- }
- }
- private void List_Click(object sender, RoutedEventArgs e)
- {
- DataBox.Items.Clear();
- List<User> users = new List<User>();
- using (var db = new AppDbContext())
- {
- var query = from b in db.User
- orderby b.Name
- select b;
- foreach(var item in query)
- {
- DataBox.Items.Add(string.Format("{0} | {1}", item.Name, item.CipherPassword));
- }
- }
- }
- private void RealPassword_Click(object sender, RoutedEventArgs e)
- {
- string key = "";
- string selected = DataBox.SelectedItem.ToString();
- string[] cipher = selected.Split(" | ");
- foreach(var pass in cipher)
- {
- Cyphered.Text = pass.ToUpper();
- }
- using (var db = new AppDbContext())
- {
- foreach(var password in db.User)
- {
- if(password.CipherPassword== Cyphered.Text)
- {
- Real.Text = originalText(Cyphered.Text, password.OriginalPassword.ToString());
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement