Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. char[] alfabet = new char[] { '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' };
  23.  
  24. label1.Text = ""+alfabet[1];
  25.  
  26. string k = textBox1.Text;
  27. string kluczdlugosci = k;
  28. string m = textBox2.Text;
  29.  
  30. label4.Text = "dlugosc m = " + m.Length;
  31.  
  32. int j = 0;
  33. int dlugosc = m.Length - k.Length;
  34.  
  35. for (int i = 0; i < dlugosc; i++)
  36. {
  37. if (i % k.Length == 0) {
  38. j = 0;
  39. }
  40. kluczdlugosci += k.Substring(j, 1);
  41. j++;
  42. }
  43.  
  44. label5.Text = "klucz dlugosci " + kluczdlugosci;
  45.  
  46. string indeksy = "";
  47. string szyfr = "";
  48. for (int i = 0; i < m.Length; i++)
  49. {
  50. char[] myChar = m.Substring(i, 1).ToCharArray();
  51. char[] myChar1 = kluczdlugosci.Substring(i, 1).ToCharArray();
  52. int indeksM = Array.IndexOf(alfabet, myChar[0]);
  53. int indeksK = Array.IndexOf(alfabet, myChar1[0]);
  54. int c = (indeksM + indeksK) % 26;
  55. indeksy += "" + indeksM + " " + indeksK + " \n";
  56.  
  57. szyfr += "" + alfabet[c+1];
  58. }
  59.  
  60. label6.Text = "" + indeksy;
  61. label7.Text = "" + szyfr;
  62.  
  63. /**/
  64.  
  65. string indeksy1 = "";
  66. string szyfr1 = "";
  67. for (int i = 0; i < m.Length; i++)
  68. {
  69. char[] myChar = szyfr.Substring(i, 1).ToCharArray();
  70. char[] myChar1 = kluczdlugosci.Substring(i, 1).ToCharArray();
  71. int indeksM = Array.IndexOf(alfabet, myChar[0]);
  72. int indeksK = Array.IndexOf(alfabet, myChar1[0]);
  73. int c = (indeksM + indeksK) % 26;
  74. indeksy += "" + indeksM + " " + indeksK + " \n";
  75.  
  76. szyfr += " " + alfabet[c + 1];
  77. }
  78.  
  79. label6.Text = "" + indeksy;
  80. label7.Text = "" + szyfr;
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement