Results 1 to 15 of 15

Thread: How to build a texteditor with crypt/decrypt?

Threaded View

  1. #13

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    11

    Re: How to build a texteditor with crypt/decrypt?

    YEA! I made it!

    This is how I did it:
    Instead of using the textbox, or a label I store it in a text file (.txt). And when I have stored the crypted text into the file, I read the file and put it into the textbox AFTER I decrypted it. And yea, it works!

    The code is REALLY bad, I have to look at it for a while.. Lot of crap.. But, it works. And that was my goal. Please dont use the code, if u do please look at it due to a lot of "bad" solutions maybe.. I am really new to Vb.

    Code:
    Dim pw As String = InputBox("Please enter the password to crypt or decrypt file. Do not forget the password, wrong password will make the file corrupt.", "Crypt or Decrypt file")
            Dim pw2 As String = InputBox("Please enter the password again to make sure it is the same.", "Crypt or Decrypt file")
    
            'If the pw is the same
            If pw = pw2 Then
    
                'Does the "tag" exist? I add this when I crypt it, and if it is there, its crypted.
                Dim r As String = TextBox1.Text()
                r = r.IndexOf("#37#37#2007#x3#39R90#")
    
                'Decrypt
                If r > 0 Then
    
    
                    Dim textboxen As String = TextBox1.Text
                    Dim krypteradtext, krypteradlasbar As String
                    'Substring where the "tag" starts. So I just work with the crypted text
                    krypteradtext = textboxen.Substring(r)
    
                    'Another substring, all text after the "tag" is crypted
                    krypteradtext = krypteradtext.Substring(21)
    
                    'Decrypt it with pw
                    krypteradlasbar = RndCrypt(krypteradtext, pw)
                    TextBox1.Text = krypteradlasbar
                Else
    
                    Dim krypterad, text, txtbox As String
                    txtbox = TextBox1.Text
                    krypterad = RndCrypt(txtbox, pw)
    
                    text = "This file is crypted. DO NOT CHANGE THIS FILE. If you do the file will be corrupt. Please open the file with EasyNote and decrypt it in order to view or change it. #37#37#2007#x3#39R90#" & krypterad
    
    
                    'Filtrera bort alla onödiga filformat
                    SaveFileDialog1.Filter = "Both *.txt and *.easynote files|*.txt;*.easynote|Text Files(*.txt)|*.txt|Easynote files(*.easynote)|*.easynote"
    
                    'Om man tryckt på Ok vid sparning
                    If SaveFileDialog1.ShowDialog = DialogResult.OK Then
    
    
                        'Skriv text till fil, FALSE säger att filen ska skapas om den inte finns.
                        Dim objWriter As New System.IO.StreamWriter(SaveFileDialog1.FileName, False)
    
    
                        objWriter.Write(text)
                        objWriter.Close()
    
                    End If
                End If
    
                'Börja läsa in filen
                Dim objReader As New System.IO.StreamReader(SaveFileDialog1.FileName)
                Dim lasintxt As String
    
                lasintxt = objReader.ReadToEnd
                objReader.Close()
    
                Dim u As String = lasintxt
                u = u.IndexOf("#37#37#2007#x3#39R90#")
    
                Dim krypteradtext2, krypteradlasbar2 As String
                krypteradtext2 = lasintxt.Substring(u)
    
                krypteradtext2 = krypteradtext2.Substring(21)
    
                krypteradlasbar2 = RndCrypt(krypteradtext2, pw)
                TextBox1.Text = krypteradlasbar2
    
            Else
                MsgBox("The password was not equal, please try again.")
    
            End If
        End Sub
    Thanks Kleinma, hopa you dont spend hours to help me out! If you do, it would be really intressting to look at your code.

    B Regs
    Johan

    EDIT: Hm... Well.. Kind of worked... Does it sometimes. Eh. Dont use the code, It has to be fixed. But I am in the right direction.
    Last edited by Johan_S; Jan 18th, 2007 at 10:11 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width