/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
using System; using System.Diagnostics; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Windows.Forms; namespace Kyrathasoft.Obfuscate { public static class serTextManip { private enum Operation{Serializing,Deserializing}; public static string DeserializeSerText(string filePath){ serText sert; try { sert = (serText)bFormatter.Deserialize(fStream); filePath = sert.TheText; if (sert.Shift) { filePath = shifted(filePath,Operation.Deserializing); } if (sert.Reverse) { filePath = stringReversed(filePath); } if ((sert.StartIndex > 0) || (sert.TheLength < sert.TheText.Length)) { filePath = filePath.Substring(sert.StartIndex, sert.TheLength); } } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { if (fStream != null) { fStream.Close(); } } return filePath; } public static void SerializeSerText(string filePath, serText stObject) { serText st = stObject; if(st.Reverse){ st.TheText = stringReversed(st.TheText);} if (st.Shift) { st.TheText = shifted(st.TheText, Operation.Serializing); } try { bFormatter.Serialize(fs, st); } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { if (fs != null) { fs.Close(); } } //end SerializePlainText, next line } private static string stringReversed(string inputString) { if (inputString == null) return null; // this was posted by petebob as well char[] array = inputString.ToCharArray(); Array.Reverse(array); string s = string.Empty; foreach (char c in array) { s += c; } return s; } private static string shifted(string inputString, Operation op) { string s = string.Empty; char[] array = inputString.ToCharArray(); int i; foreach (char c in array) { if(op == Operation.Serializing){ i = Convert.ToInt32((int)c) + 1; }else{ i = Convert.ToInt32((int)c)-1; } s += (char)i; } return s; } //end class next line } }