Encode/Decode Using ASC With Key In PowerBuilder
Source Code
Encode ASC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
String ls_encrypt Long ll_char, ll_chars, ll_keychars String as_source, as_Key as_Key = "SecretKey" as_Source = "https://pblib.com/" // Check for null arguments If IsNull(as_source) Or IsNull(as_key) Then SetNull(ls_encrypt) Return End If // Check for empty arguments ll_chars = Len(as_source) ll_keychars = Len(as_key) If ll_chars < 1 Or ll_keychars < 1 Then Return '' // Encrypt the string ls_encrypt = '' For ll_char = 1 To ll_chars ls_encrypt += String(Char(Asc(Mid(as_source, ll_char, 1)) + Asc(Mid(as_key,Mod(ll_char, ll_keychars) + 1, 1)))) Next //Return ls_encrypt |
Decode ASC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
String ls_decrypt Long ll_char, ll_chars, ll_keychars String as_source, as_Key as_Key = "SecretKey" as_Source = 'Í×æÕç
¨Ã×ÒÙ×Õ¸ÒâÁÌÐ×ÙܺÉì¼ÙÕÔáz' // Check for null arguments If IsNull(as_source) Or IsNull(as_key) Then SetNull(ls_decrypt) Return End If // Check for empty arguments ll_chars = Len(as_source) ll_keychars = Len(as_key) If ll_chars < 1 Or ll_keychars < 1 Then Return '' // Decrypt the string ls_decrypt = '' For ll_char = 1 To ll_chars ls_decrypt += String(Char(Asc(Mid(as_source, ll_char, 1)) - Asc(Mid(as_key,Mod(ll_char, ll_keychars) + 1, 1)))) Next //Return ls_decrypt |
Source Example
w_main from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
forward global type w_main from window end type type sle_key from singlelineedit within w_main end type type st_3 from statictext within w_main end type type st_2 from statictext within w_main end type type st_1 from statictext within w_main end type type mle_output from multilineedit within w_main end type type mle_input from multilineedit within w_main end type type cb_decode from commandbutton within w_main end type type cb_encode from commandbutton within w_main end type end forward global type w_main from window integer width = 2318 integer height = 1328 boolean titlebar = true string title = "Encrypt/Dencrypt ASC With Key" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true sle_key sle_key st_3 st_3 st_2 st_2 st_1 st_1 mle_output mle_output mle_input mle_input cb_decode cb_decode cb_encode cb_encode end type global w_main w_main type prototypes end prototypes forward prototypes public function string wf_encode (string as_source, string as_key) public function string wf_decode (string as_source, string as_key) end prototypes public function string wf_encode (string as_source, string as_key);//==================================================================== // Function: w_main.wf_encode() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_source // value string as_key //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/01/06 //-------------------------------------------------------------------- // Usage: w_main.wf_encode ( string as_source, string as_key ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_encrypt Long ll_char, ll_chars, ll_keychars // Check for null arguments If IsNull(as_source) Or IsNull(as_key) Then SetNull(ls_encrypt) Return ls_encrypt End If // Check for empty arguments ll_chars = Len(as_source) ll_keychars = Len(as_key) If ll_chars < 1 Or ll_keychars < 1 Then Return '' // Encrypt the string ls_encrypt = '' For ll_char = 1 To ll_chars ls_encrypt += String(Char(Asc(Mid(as_source, ll_char, 1)) + Asc(Mid(as_key,Mod(ll_char, ll_keychars) + 1, 1)))) Next Return ls_encrypt end function public function string wf_decode (string as_source, string as_key);//==================================================================== // Function: w_main.wf_decode() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_source // value string as_key //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/01/06 //-------------------------------------------------------------------- // Usage: w_main.wf_decode ( string as_source, string as_key ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_decrypt Long ll_char, ll_chars, ll_keychars // Check for null arguments If IsNull(as_source) Or IsNull(as_key) Then SetNull(ls_decrypt) Return ls_decrypt End If // Check for empty arguments ll_chars = Len(as_source) ll_keychars = Len(as_key) If ll_chars < 1 Or ll_keychars < 1 Then Return '' // Decrypt the string ls_decrypt = '' For ll_char = 1 To ll_chars ls_decrypt += String(Char(Asc(Mid(as_source, ll_char, 1)) - Asc(Mid(as_key,Mod(ll_char, ll_keychars) + 1, 1)))) Next Return ls_decrypt end function on w_main.create this.sle_key=create sle_key this.st_3=create st_3 this.st_2=create st_2 this.st_1=create st_1 this.mle_output=create mle_output this.mle_input=create mle_input this.cb_decode=create cb_decode this.cb_encode=create cb_encode this.Control[]={this.sle_key,& this.st_3,& this.st_2,& this.st_1,& this.mle_output,& this.mle_input,& this.cb_decode,& this.cb_encode} end on on w_main.destroy destroy(this.sle_key) destroy(this.st_3) destroy(this.st_2) destroy(this.st_1) destroy(this.mle_output) destroy(this.mle_input) destroy(this.cb_decode) destroy(this.cb_encode) end on type sle_key from singlelineedit within w_main integer x = 366 integer y = 32 integer width = 951 integer height = 96 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "SecretKey" borderstyle borderstyle = stylelowered! end type type st_3 from statictext within w_main integer x = 64 integer y = 696 integer width = 343 integer height = 76 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Output Text:" boolean focusrectangle = false end type type st_2 from statictext within w_main integer x = 64 integer y = 180 integer width = 329 integer height = 76 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Input Text:" boolean focusrectangle = false end type type st_1 from statictext within w_main integer x = 50 integer y = 44 integer width = 315 integer height = 76 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Secret Key:" boolean focusrectangle = false end type type mle_output from multilineedit within w_main integer x = 50 integer y = 784 integer width = 2167 integer height = 400 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type mle_input from multilineedit within w_main integer x = 50 integer y = 260 integer width = 2167 integer height = 400 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "https://pblib.com/" borderstyle borderstyle = stylelowered! end type type cb_decode from commandbutton within w_main integer x = 1664 integer y = 32 integer width = 297 integer height = 96 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Decode" end type event clicked;String ls_input, ls_key, ls_output ls_key = sle_key.Text ls_input = mle_input.Text ls_output = wf_decode(ls_input, ls_key) mle_output.Text = ls_output end event type cb_encode from commandbutton within w_main integer x = 1353 integer y = 32 integer width = 297 integer height = 96 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Encode" end type event clicked;String ls_input, ls_key, ls_output ls_key = sle_key.Text ls_input = mle_input.Text ls_output = wf_encode(ls_input, ls_key) mle_output.Text = ls_output end event |
Find Projects On Github click here
Subscribe
Login
0 Comments
Oldest