|
|
вернуться в форумUsing OOP (C#) using System; namespace EasyHack_ { class Coder { private short[] unicode; private string word; public static readonly string alphabet = "abcdefghijklmnopqrstuvwxyz"; public string GetCoderWord() { this.UnicodeToCoder(); this.SetUnicode(); return this.word; } public string GetOutCoderWord() { this.UnicodeOutCoder(); this.SetUnicode(); return this.word; } public Coder(string word) { this.word = word.ToLower(); this.unicode = new short[word.Length]; this.GetUnicode(); }
public string GetWord () { return this.word; } public short[] GetWordUnicode () { return this.unicode; } private void GetUnicode () { for (int iterable = 0; iterable < unicode.Length; iterable++) { this.unicode[iterable] = (short)Coder.alphabet.IndexOf(this.word[iterable]); } } private void SetUnicode () { this.word = ""; for (int iterable = 0; iterable < unicode.Length; iterable++) { this.word += Coder.alphabet[unicode[iterable]]; } } private void UnicodeToCoder () { if (unicode[0] == 21) unicode[0] = 0; else this.unicode[0] = (this.unicode[0] + 5 > 25) ? (short)(this.unicode[0] + 5 - 25) : (short)(this.unicode[0] + 5); for (int iterable = 1; iterable < this.unicode.Length; iterable++) { this.unicode[iterable] = (this.unicode[iterable] + this.unicode[iterable - 1] > 25) ? (short)((this.unicode[iterable] + this.unicode[iterable - 1]) % 26) : (short)(this.unicode[iterable] + this.unicode[iterable - 1]); } } private void UnicodeOutCoder () { for (int iterable = 1; iterable < this.unicode.Length; iterable++) { while (this.unicode[iterable] < this.unicode[iterable - 1]) this.unicode[iterable] += 26; } short _lastUnicode = this.unicode[0]; if (this.unicode[0] == 0) this.unicode[0] = 21; else this.unicode[0] = (this.unicode[0] - 5 < 0) ? (short)(25 + this.unicode[0] - 5) : (short)(this.unicode[0] - 5); for (int iterable = 0; iterable < this.unicode.Length - 1; iterable++) { short element = this.unicode[iterable + 1]; this.unicode[iterable + 1] -= _lastUnicode; _lastUnicode = element; } } } class Program { public static void Main(string[] args) { string coderWord = Console.ReadLine(); Coder word = new Coder(coderWord); Console.WriteLine(word.GetOutCoderWord()); } } } Edited by author 31.10.2021 14:59 Edited by author 31.10.2021 15:11 |
|
|