57 lines
2.4 KiB
Plaintext
57 lines
2.4 KiB
Plaintext
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();
|
|
|
|
/// <summary>
|
|
/// Encrypt a string with the cipher
|
|
/// </summary>
|
|
/// <param name="workSpace">The working copy of the cipher</param>
|
|
/// <param name="inputText">The original cipher</param>
|
|
/// <param name="line">The user input</param>
|
|
/// <returns>The encrypted string</returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Decrypt a string with the cipher
|
|
/// </summary>
|
|
/// <param name="workSpace">The working copy of the cipher</param>
|
|
/// <param name="inputText">The original cipher</param>
|
|
/// <param name="line">The user input</param>
|
|
/// <returns>The encrypted string</returns>
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|