using System; using System.Linq; using System.IO; using System.Text; using System.Collections.Generic; namespace AniNIX.Crypto { public class Ubchi : Cipher { public override String Description() { return "The Ubchi cipher\nThis is a regular double-transposition cipher -- it will add some garbage to the end of your string.\nKey format is any word to use for the transposition.\nNOTE: This does not completely match Rumkin, whose implementation is a little flawed."; } public override String Command() { return "ubchi"; } public Ubchi(Workbench w) : base (w) {} private ColumnTransposition col = new ColumnTransposition(); /// /// Encrypt a string with the cipher /// /// The working copy of the cipher /// The original cipher /// The user input /// The encrypted string public override String Encrypt(String workSpace,String inputText,String[] line) { if (line == null || line.Length != 3) { Console.Error.WriteLine("Malformed!"); return workSpace; } // Pad the incoming workspace String changed = CharGrid.RandPad(workSpace,line[2].Length); // Transpose twice. changed = col.Encrypt(changed,inputText,line); changed = col.Encrypt(changed,inputText,line); return changed; } /// /// Decrypt a string with the cipher /// /// The working copy of the cipher /// The original cipher /// The user input /// The encrypted string public override String Decrypt(String workSpace,String inputText,String[] line) { if (line == null || line.Length != 3) { Console.Error.WriteLine("Malformed!"); return workSpace; } // De-transpose twice. Without encrypting a number, we don't have a way to programmatically trim. String changed = col.Decrypt(workSpace,inputText,line); changed = col.Decrypt(changed,inputText,line); return changed; } } }