fork download
  1. Imports Microsoft.VisualBasic
  2. Imports System
  3.  
  4. ''' <summary>
  5. '''*************************************************
  6. ''' Copyright (C) 2000 MIND
  7. ''' All rights reserved.
  8. ''' The information contained here in is confidential and *proprietary to MIND and forms the part of the MIND
  9. ''' CREATED BY : Samir Ranjan PAdhi
  10. ''' Date : 22/06/2007 (DD/MM/YYYY format)
  11. ''' Description : class for encryption technique
  12. ''' **Project : GAS
  13. ''' </summary>
  14.  
  15. Namespace com.azilon.common.security
  16. ''' <summary>
  17. ''' @author Samir Ranjan Padhi
  18. '''
  19. ''' To change the template for this generated type comment go to
  20. ''' Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  21. ''' </summary>
  22.  
  23. Public Class Password_Enc_Dec
  24. ''' <summary>
  25. '''************************************************************
  26. ''' Method :encrypt(String oldPassword)
  27. ''' Return Values() :void
  28. ''' Parameter(s) :String oldPassword
  29. ''' Purpose :This method is for encrypt the string value
  30. ''' Developed by :Luxmi Nagda
  31. ''' </summary>
  32. Public Overridable Function encrypt(ByVal oldPassword As String) As String
  33. Dim len As Integer=oldPassword.Length
  34. Dim newPassword As String=""
  35. Dim temp(len - 1) As Integer
  36. Dim i As Integer=0
  37. Dim ran As Integer=CInt(Fix(Math.Floor((New Random(1)).NextDouble()*256)+1))
  38. Dim ch As Integer
  39. For i = 0 To len - 1
  40. ch= AscW(oldPassword.Chars(i))
  41. temp(i)=Convert.ToInt32("" & ch)
  42. If (temp(i)>=0) AndAlso (temp(i)<64) Then
  43. temp(i) +=128
  44. ElseIf (temp(i)>=64) AndAlso (temp(i)<128) Then
  45. temp(i) +=128
  46. ElseIf (temp(i)>=128) AndAlso (temp(i)<192) Then
  47. temp(i) -=128
  48. ElseIf (temp(i)>=192) AndAlso (temp(i)<256) Then
  49. temp(i) -=128
  50. Else
  51.  
  52. End If
  53. temp(i) +=ran
  54. newPassword +=convertToBoolean(temp(i))
  55. Next i
  56. newPassword +=convertToBoolean(ran)
  57. Return newPassword
  58. End Function
  59.  
  60.  
  61. ''' <summary>
  62. '''************************************************************
  63. ''' Method :decryptInDecimal(String password)
  64. ''' Return Values() :void
  65. ''' Parameter(s) :String password
  66. ''' Purpose :This method is for decrypt the encrypted boolean value into decimalvalue without the random no.
  67. ''' Developed by :Luxmi Nagda
  68. ''' </summary>
  69. Public Overridable Function decryptInDecimal(ByVal password As String) As String
  70. Dim len As Integer=password.Length
  71. Dim oldPassword As String=""
  72. Dim pwdLen As Integer=((len\9)-1)
  73. Dim temp(pwdLen - 1) As Integer
  74. Dim k As Integer=0
  75. Dim ran As Integer
  76.  
  77.  
  78. Dim strbooleantemp As String=""
  79. Dim strbooleanRan As String=password.Substring(len-9)
  80. ran=convertToDecimal(strbooleanRan)
  81.  
  82. For k = 0 To (pwdLen) - 1
  83. strbooleantemp=password.Substring((9*k), 9*(k+1) - ((9*k)))
  84. temp(k)=(convertToDecimal(strbooleantemp)-ran)
  85. oldPassword +=temp(k) & ""
  86. Next k
  87. Return oldPassword
  88. End Function
  89.  
  90.  
  91. ''' <summary>
  92. '''************************************************************
  93. ''' Method :decryptFromDecimalToString(String password)
  94. ''' Return Values() :void
  95. ''' Parameter(s) :String password
  96. ''' Purpose :This method decrypt the decimal value(that is stored in database without random no) into actual string value
  97. ''' Developed by :Luxmi Nagda
  98. ''' </summary>
  99. Public Overridable Function decryptFromDecimalToString(ByVal password As String) As String
  100. Dim len As Integer=password.Length
  101. Dim oldPassword As String=""
  102. Dim pwdLen As Integer=(len\3)
  103. Dim temp(pwdLen - 1) As Integer
  104. Dim k As Integer=0
  105. Dim p As Char
  106. Dim strbooleantemp As String=""
  107. For k = 0 To (pwdLen) - 1
  108. strbooleantemp=password.Substring((3*k), 3*(k+1) - ((3*k)))
  109. temp(k)=Convert.ToInt32(strbooleantemp)
  110.  
  111. If (temp(k)>=0) AndAlso (temp(k)<64) Then
  112. temp(k) +=128
  113. ElseIf (temp(k)>=64) AndAlso (temp(k)<128) Then
  114. temp(k) +=128
  115. ElseIf (temp(k)>=128) AndAlso (temp(k)<192) Then
  116. temp(k) -=128
  117. ElseIf (temp(k)>=192) AndAlso (temp(k)<256) Then
  118. temp(k) -=128
  119. Else
  120.  
  121. End If
  122.  
  123. p=ChrW(temp(k))
  124. oldPassword +=p
  125. Next k
  126. Return oldPassword
  127. End Function
  128.  
  129.  
  130. ''' <summary>
  131. '''************************************************************
  132. ''' Method :convertToDecimal(String password)
  133. ''' Return Values() :void
  134. ''' Parameter(s) :String strbooleancode
  135. ''' Purpose :This method is for converting the boolean value to decimal value.
  136. ''' Developed by :Luxmi Nagda
  137. ''' </summary>
  138. Public Overridable Function convertToDecimal(ByVal strbooleancode As String) As Integer
  139. Dim i As Integer = 0
  140. Dim j As Integer = 0
  141. Dim result As Integer = 0
  142. Dim base As Integer = 2
  143. Dim temp As Char = "-"c
  144. i=0
  145. j=8
  146. Do While i<9
  147. temp=strbooleancode.Chars(i)
  148. result += Math.Pow(base,j)*Convert.ToInt32("" & AscW(temp))
  149. i += 1
  150. j -= 1
  151. Loop
  152. Return result
  153. End Function
  154. ''' <summary>
  155. '''************************************************************
  156. ''' Method :convertToBoolean(String password)
  157. ''' Return Values() :void
  158. ''' Parameter(s) :int intcode
  159. ''' Purpose :This method is for converting the decimal value to boolean value.
  160. ''' Developed by :Luxmi Nagda
  161. ''' </summary>
  162. Public Overridable Function convertToBoolean(ByVal intcode As Integer) As String
  163. Dim num As Integer=intcode
  164. Dim quot As Integer
  165. Dim div As Integer=2
  166. Dim [rem] As Integer
  167. Dim temp(8) As Integer
  168. Dim temp2(8) As Integer
  169. Dim len As Integer=temp.Length
  170. Dim str As String=""
  171. Dim k As Integer=0
  172. k=0
  173. Do While num<>0
  174. quot=num\div
  175. [rem]=num Mod div
  176. temp(k)=[rem]
  177. num=quot
  178. k += 1
  179. Loop
  180. ' for suffixing zeros to make it 9bit.
  181. For i As Integer = k To len - 1
  182. temp(i)=0
  183. Next i
  184. ' For storing valuesreversing array
  185. Dim i As Integer=len-1
  186. Dim j As Integer=0
  187. Do While i>=0
  188. temp2(j)=temp(i)
  189. i -= 1
  190. j += 1
  191. Loop
  192. ' for converting array to string value.
  193. For i As Integer = 0 To len - 1
  194. str +=temp2(i)
  195. Next i
  196. Return str
  197. End Function
  198. ''' <summary>
  199. '''************************************************************
  200. ''' Method :convertToBoolean(String password)
  201. ''' Return Values() :void
  202. ''' Parameter(s) :int intcode
  203. ''' Purpose :This method is for converting the boolean value to String.
  204. ''' Developed by :Luxmi Nagda
  205. ''' </summary>
  206.  
  207. Public Overridable Function decrypt(ByVal password As String) As String
  208. Dim len As Integer=password.Length
  209. Dim oldPassword As String=""
  210. Dim pwdLen As Integer=((len\9)-1)
  211. Dim temp(pwdLen - 1) As Integer
  212. Dim k As Integer=0
  213. Dim ran As Integer
  214. Dim p As Char
  215. Dim strbooleantemp As String=""
  216. Dim strbooleanRan As String=password.Substring(len-9)
  217. ran=convertToDecimal(strbooleanRan)
  218.  
  219. For k = 0 To (pwdLen) - 1
  220. strbooleantemp=password.Substring((9*k), 9*(k+1) - ((9*k)))
  221. temp(k)=(convertToDecimal(strbooleantemp)-ran)
  222.  
  223. If (temp(k)>=0) AndAlso (temp(k)<64) Then
  224. temp(k) +=128
  225. ElseIf (temp(k)>=64) AndAlso (temp(k)<128) Then
  226. temp(k) +=128
  227. ElseIf (temp(k)>=128) AndAlso (temp(k)<192) Then
  228. temp(k) -=128
  229. ElseIf (temp(k)>=192) AndAlso (temp(k)<256) Then
  230. temp(k) -=128
  231. Else
  232.  
  233. End If
  234.  
  235. p=ChrW(temp(k))
  236. oldPassword +=p
  237. Next k
  238. Return oldPassword
  239. End Function
  240.  
  241.  
  242.  
  243. Shared Sub Main(ByVal arg() As String)
  244.  
  245. Dim pwdEncDecription As New Password_Enc_Dec()
  246. Console.WriteLine(pwdEncDecription.decryptInDecimal(pwdEncDecription.encrypt("172.29.55.218")))
  247. Console.WriteLine((pwdEncDecription.decryptFromDecimalToString("177183178174178185174181181174178177184")))
  248.  
  249. End Sub
  250. End Class
  251.  
  252. End Namespace
Runtime error #stdin #stdout 0.14s 36856KB
stdin
Standard input is empty
stdout
Standard output is empty