Page 1 of 1

Creating an Encryption Program Encryption Program - The Other Way Rate Topic: ***** 1 Votes

#1 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 50
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

Post icon  Posted 26 January 2009 - 07:31 PM

This time i've included all info through comments in the code.


Private Sub Command1_Click()
Dim a As String
Dim B As String
a$ = Text1.text 'Text to encrypt
B$ = Text2.text 'Password
'encrypting text with a return to text1
Text1.text = Encrypt(a$, B$, True) 'true = Encrypt
End Sub




Explanation : Command1 is a Command Button used to Encrypt text



Private Sub Command2_Click()
Dim a As String
Dim B As String
a$ = Text1.text 'Text to decrypt
B$ = Text2.text 'Password
'decrypting text with a return to text1
Text1.text = Encrypt(a$, B$, False) 'false = decrypt
End Sub




Explanation : Command2 is a command button to decrypt.


==================Encrypt Function ===================

Function Encrypt(text As String, pw As String, type_of As Boolean) As String
'Declaring variables
Dim x As Integer
Dim i As Integer
Dim a As Integer
Dim text_chr As String
Dim text_asc As Integer
Dim pw_chr As String
Dim pw_asc As Integer
Dim fin As String
Dim fin_chr As String
Dim fin_asc As Integer

'if type_of = true then Encrypt
'if type_of = False then Decrypt
Call percent(Picture1, 0) 'clear percent
'making sure there is text to encrypt and a password
'to go with it
If Len(text$) = 0 Then Exit Function
If Len(pw$) = 0 Then Exit Function

x% = 1
'the X variable is the loop that goes through the password
'characters individually through the encrpytion processes
'X = 1 to set the loop at the first character
For i% = 1 To Len(text$) 'start of encrpyt loop
	'taking out characters from text to encrypt
	'the single character
	text_chr$ = Mid(text$, i, 1)
	'changing the character to its ASCII value to
	'easily change the character for encrypting
	text_asc% = Asc(text_chr$)
	'doing the same process with the password
	'using the X variable
	pw_chr$ = Mid(pw$, x, 1)
	pw_asc% = Asc(pw_chr$)
	'adding up variable to continue loop through different
	'characters within the password
	x% = x% + 1
	If x% > Len(pw$) Then x% = 1 'restarting password loop
	'Case to check if the user is Encrypting or Decrypting the text
	Select Case type_of
	Case True: 'Encrypting
		'adding the characters of both string and password
		fin_asc% = text_asc% + pw_asc%
		'making sure the final_asc will equal a valid ASCII character
		If fin_asc% > 255 Then
			'Character was an invalid character so we modify it
			'to equal a valid character
			a% = fin_asc% - 255
			fin_chr$ = Chr$(a%)
		Else
			'character was valid;D
			fin_chr$ = Chr$(fin_asc%)
		End If
	Case False: 'Decrypting
		'here we subtract the characters...does the opposite of
		'what encrypting does to put it back in its
		'original state, which is why it's called Decrypting
		fin_asc% = text_asc% - pw_asc% 'subtracting character values
		If fin_asc% < 1 Then   'checking for invalid character
			'invalid character..fixing problem =)
			a% = fin_asc% + 255
			fin_chr$ = Chr$(a%)
		Else
			'it was all good.
			fin_chr$ = Chr$(fin_asc%)
		End If
	End Select 'End of case
	'adding the final encrypted character to a string
	'to be later shown in its final state at the end
	fin$ = fin$ & fin_chr$
	'thought i'd be mr. fancy pants by adding a little
	'percentage bar =)
	Call percent(Picture1, CInt((i / Len(text) * 100)))
Next 'continuing loop =)
'finalizing function to equal the final encrypted string
Encrypt$ = fin$
DoEvents
Call percent(Picture1, 0)
End Function




NOTE : For details, carefully go through the Comments.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating an Encryption Program

#2 bayron.jofel  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 16-April 09

Posted 12 August 2009 - 09:56 AM

what's the use of $ this sign for your variable

View Postbayron.jofel, on 12 Aug, 2009 - 08:55 AM, said:

what's the use of $ this sign for your variable a and b

Was This Post Helpful? 0
  • +
  • -

#3 cripplewarlord  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-September 09

Posted 25 September 2009 - 11:48 PM

View Postbayron.jofel, on 12 Aug, 2009 - 08:56 AM, said:

what's the use of $ this sign for your variable

View Postbayron.jofel, on 12 Aug, 2009 - 08:55 AM, said:

what's the use of $ this sign for your variable a and b
i keep getting a error it says expected end sub at the a$ bit ??
Was This Post Helpful? 0
  • +
  • -

#4 matsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-October 09

Posted 26 October 2009 - 04:26 AM

Nice it actually worked :)

All you haft to do is to remove all:
Call percent(Picture1, 0)
Call percent(Picture1, 0)
Call percent(Picture1, CInt((i / Len(text) * 100)))



ONLY TRIED IT IN VB6

HOPE THIS HELPED!
Was This Post Helpful? 0
  • +
  • -

#5 arakinas  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 07-December 11

Posted 07 December 2011 - 06:25 AM

View Postbayron.jofel, on 12 August 2009 - 09:56 AM, said:

what's the use of $ this sign for your variable

View Postbayron.jofel, on 12 Aug, 2009 - 08:55 AM, said:

what's the use of $ this sign for your variable a and b

I wondered the same thing. I found this from MSDN which explains that certain special characters can be used to help identify the type of variable.
http://msdn.microsof...y/s9cz43ek.aspx
Was This Post Helpful? 0
  • +
  • -

#6 Fredex  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 86
  • Joined: 16-January 12

Posted 09 March 2012 - 09:49 PM

What will happen if I remove the dollar and percent signs?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1