Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. using SaugumasPirmasPD.DbContextApp;
  2. using SaugumasPirmasPD.Model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17.  
  18. namespace SaugumasPirmasPD
  19. {
  20.  
  21. public partial class MainWindow : Window
  22. {
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26.  
  27. }
  28. string keyword = "AYUSH";
  29.  
  30. public string generateKey(string str, string key)
  31. {
  32. int x = str.Length;
  33.  
  34. for (int i = 0; ; i++)
  35. {
  36. if (x == i)
  37. i = 0;
  38. if (key.Length == str.Length)
  39. break;
  40. key += (key[i]);
  41. }
  42. return key;
  43. }
  44. static string cipherText(string str, string key)
  45. {
  46. string cipher_text = "";
  47.  
  48. for (int i = 0; i < str.Length; i++)
  49. {
  50.  
  51. int x = (str[i] + key[i]) % 26;
  52.  
  53. x += 'A';
  54.  
  55. cipher_text += (char)(x);
  56. }
  57. return cipher_text;
  58. }
  59.  
  60.  
  61. static String originalText(String cipher_text, String key)
  62. {
  63. String orig_text = "";
  64.  
  65. for (int i = 0; i < cipher_text.Length &&
  66. i < key.Length; i++)
  67. {
  68. // converting in range 0-25
  69. int x = (cipher_text[i] -
  70. key[i] + 26) % 26;
  71.  
  72. // convert into alphabets(ASCII)
  73. x += 'A';
  74. orig_text += (char)(x);
  75. }
  76. return orig_text;
  77. }
  78. private void Crypt_Click(object sender, RoutedEventArgs e)
  79. {
  80. string str = Pass.Text;
  81. string str1=str.ToUpper();
  82. string key = generateKey(str1, keyword);
  83. string smth = cipherText(str1, key);
  84. using (var db = new AppDbContext())
  85. {
  86. var user = new User { Name = Name.Text, CipherPassword = smth, OriginalPassword= key };
  87. db.User.Add(user);
  88. db.SaveChanges();
  89. }
  90.  
  91. }
  92.  
  93. private void List_Click(object sender, RoutedEventArgs e)
  94. {
  95. DataBox.Items.Clear();
  96. List<User> users = new List<User>();
  97. using (var db = new AppDbContext())
  98. {
  99. var query = from b in db.User
  100. orderby b.Name
  101. select b;
  102. foreach(var item in query)
  103. {
  104. DataBox.Items.Add(string.Format("{0} | {1}", item.Name, item.CipherPassword));
  105. }
  106.  
  107. }
  108. }
  109.  
  110. private void RealPassword_Click(object sender, RoutedEventArgs e)
  111. {
  112. string key = "";
  113. string selected = DataBox.SelectedItem.ToString();
  114. string[] cipher = selected.Split(" | ");
  115. foreach(var pass in cipher)
  116. {
  117. Cyphered.Text = pass.ToUpper();
  118. }
  119. using (var db = new AppDbContext())
  120. {
  121. foreach(var password in db.User)
  122. {
  123. if(password.CipherPassword== Cyphered.Text)
  124. {
  125.  
  126. Real.Text = originalText(Cyphered.Text, password.OriginalPassword.ToString());
  127. }
  128. }
  129. }
  130.  
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement