文本混淆-第二部分,共二部分

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文本混淆-第二部分,共二部分相关的知识,希望对你有一定的参考价值。

  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5. using System.Windows.Forms;
  6.  
  7. namespace Kyrathasoft.Obfuscate {
  8.  
  9. public static class serTextManip {
  10.  
  11. private enum Operation{Serializing,Deserializing};
  12.  
  13. public static string DeserializeSerText(string filePath){
  14. serText sert;
  15. FileStream fStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None);
  16. try {
  17. BinaryFormatter bFormatter = new BinaryFormatter();
  18. sert = (serText)bFormatter.Deserialize(fStream);
  19. filePath = sert.TheText;
  20. if (sert.Shift) {
  21. filePath = shifted(filePath,Operation.Deserializing);
  22. }
  23. if (sert.Reverse) {
  24. filePath = stringReversed(filePath);
  25. }
  26. if ((sert.StartIndex > 0) || (sert.TheLength < sert.TheText.Length)) {
  27. filePath = filePath.Substring(sert.StartIndex, sert.TheLength);
  28. }
  29. } catch (Exception exception) {
  30. MessageBox.Show(exception.Message);
  31. } finally {
  32. if (fStream != null) {
  33. fStream.Close();
  34. }
  35. }
  36.  
  37.  
  38.  
  39. return filePath;
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. public static void SerializeSerText(string filePath, serText stObject) {
  48. serText st = stObject;
  49. if(st.Reverse){ st.TheText = stringReversed(st.TheText);}
  50. if (st.Shift) { st.TheText = shifted(st.TheText, Operation.Serializing); }
  51.  
  52. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
  53. try {
  54. BinaryFormatter bFormatter = new BinaryFormatter();
  55. bFormatter.Serialize(fs, st);
  56. }
  57. catch (Exception exception) {
  58. MessageBox.Show(exception.Message);
  59. }
  60. finally {
  61. if (fs != null) {
  62. fs.Close();
  63. }
  64. }
  65. //end SerializePlainText, next line
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. private static string stringReversed(string inputString) {
  74. if (inputString == null) return null;
  75.  
  76. // this was posted by petebob as well
  77. char[] array = inputString.ToCharArray();
  78. Array.Reverse(array);
  79. string s = string.Empty;
  80. foreach (char c in array) {
  81. s += c;
  82. }
  83. return s;
  84. }
  85.  
  86.  
  87. private static string shifted(string inputString, Operation op) {
  88. string s = string.Empty;
  89. char[] array = inputString.ToCharArray();
  90. int i;
  91. foreach (char c in array) {
  92. if(op == Operation.Serializing){
  93. i = Convert.ToInt32((int)c) + 1;
  94. }else{
  95. i = Convert.ToInt32((int)c)-1;
  96. }
  97. s += (char)i;
  98. }
  99. return s;
  100. }
  101.  
  102.  
  103. //end class next line
  104. }
  105.  
  106. }

以上是关于文本混淆-第二部分,共二部分的主要内容,如果未能解决你的问题,请参考以下文章

C++探索之旅第二部分第一课:面向对象初探,string的惊天内幕

第一届绿色计算大赛 第二部分第三道题 石头

实验二 第二部分

实验二 第二部分

实验二 第二部分

crypto实验报告