Advertisement
StoneHaos

sofa4ib

Jan 17th, 2022
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace sofa4 {
  5.     class Program {
  6.  
  7.         static long gamma = 137438691328;
  8.         static long cur_gamma = gamma;
  9.         static void Main(string[] args) {
  10.             string a = "привет, мир!";
  11.             string b = Shifr(a);
  12.             string c = Deshifr(b);
  13.             Console.WriteLine(a);
  14.             Console.WriteLine(b);
  15.             Console.WriteLine(c);
  16.         }
  17.  
  18.         static string Shifr(string message) {
  19.             cur_gamma = gamma;
  20.             StringBuilder ret = new StringBuilder(message.ToLower().Replace('ё', 'е'));
  21.             for (int i = 0; i < ret.Length; ++ i) {
  22.                 int c = Convert.ToInt32(ret[i]);
  23.                 if (c < 1072 || c > 1103) continue;
  24.                 c = (c - 1072 + (int)(cur_gamma % 10)) % 32 + 1072;
  25.                 ret[i] = Convert.ToChar(c);
  26.                 cur_gamma /= 10;
  27.                 if (cur_gamma == 0) cur_gamma = gamma;
  28.             }
  29.             return ret.ToString();
  30.         }
  31.  
  32.         static string Deshifr(string message) {
  33.             cur_gamma = gamma;
  34.             StringBuilder ret = new StringBuilder(message.ToLower().Replace('ё', 'е'));
  35.             for (int i = 0; i < ret.Length; ++ i) {
  36.                 int c = Convert.ToInt32(ret[i]);
  37.                 if (c < 1072 || c > 1103) continue;
  38.                 c = (c - 1072 + 32 - (int)(cur_gamma % 10)) % 32 + 1072;
  39.                 ret[i] = Convert.ToChar(c);
  40.                 cur_gamma /= 10;
  41.                 if (cur_gamma == 0) cur_gamma = gamma;
  42.             }
  43.             return ret.ToString();
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement