Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Jak zrobić program, który zastępuje znaki?


Rekomendowane odpowiedzi

Opublikowano

tak jak w temacie czyli Jak zrobić program, który zastępuje znaki? 

 

 

chodzi o to że są dwa pola tekstowe (textbox) i jeden przycisk  , i w pierwszym polu tekstowym (textbox1) piszesz jakieś słowa na przykład SIEMA a potem klikasz przycisk i w drugim pojawia się tekst ze zmienionymi znakami czyli w skrócie chce zrobić program do szyfrowania

 

 

załóżmy że literka S to litera a a litera i to liera g a litera e to litera p a litera m to litera h a litera a to litera m

 

no to jak wpiszemy słowo SIEMA to w po kliknięciu przycisku pojawia się w tym drugim polu tekstowym (textbox2) taki tekst: "agphm"

 

czyli te literki się zmieniły na te co były ustawione w kodzie czyli program jak by musi wykryć jakie są literki w tym teksie i każdą literkę zmienia na jakiś inny znak 

 

czyli  napisze w polu tekstowym na przykład samą literke A to po kliknięciu przycisku się pojawia w drugim polu literka M 

 

 

jak to by można zrobić ?

Opublikowano

 

 

to jest szyfrowanie MD5 a ja chce własne szyfrowanie czyli w kodzie sobie mogę ustawić na co dany znak ma się zmieniać czyli jak ustawie w kodzie że literka a to litera e to napisze w pierwszym textbox'ie jakieś zdanie które ma literki a to jak kliknę przycisk to każda litera a zmieni się na e

Opublikowano

https://msdn.microsoft.com/en-us/library/czx8s9ts(v=vs.110).aspx

Class stringReplace1
Public Shared Sub Main()
Dim str As [String] = "1 2 3 4 5 6 7 8 9"
Console.WriteLine("Original string: ""{0}""", str)
Console.WriteLine("CSV string: ""{0}""", str.Replace(" "c, ","c))
End Sub 
End Class 
' This example produces the following output: 
' Original string: "1 2 3 4 5 6 7 8 9" 
' CSV string: "1,2,3,4,5,6,7,8,9"

Zmiana spacji na przecinek ;).. przeanalizuj kod.

 

no i string replace

https://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx 

Opublikowano

pisałem taki temat też na dwóch innych forach i w jednym opisał mi jeden gość to:

You will use String.Replace. Assuming that your two text fields are TextBox controls and that their names are TextBox1 and TextBox2, take a look at this example:
Code:

TextBox2.Text = TextBox1.Text.Replace("Original Value", "Replace Value")

a na drugim podawali mi tyle przykładów że szok:

 

1.

' -- [Encript] button: click
' cf. [ASCII code]  0 ~ 127,  visible character = 32~126
Private Sub btnEncrypt_Click(sender As Object, e As EventArgs) Handles btnEncrypt.Click
    If Me.txtInput.Text.Length = 0 Then
        Me.txtInput.Text = "Input here!"
        Exit Sub
    End If
    ' -- clear Encrypted text
    Me.txtEncrypted.Text = ""
    ' -- Loop 0 ~ (the number of input characters - 1)
    Dim chrInput As String		' input character (1 character)
    Dim intASCII As Integer		' ACSII code (0~127,  visible character = 32~126)
    Dim intShifted As Integer	' integer: shifted + 1 
    Dim chrEncrypted As String	' encrypted character
    For idx As Integer = 0 To Me.txtInput.Text.Length - 1
        ' -- convert a character to ASCII code(integer)
        chrInput = Me.txtInput.Text.Substring(idx, 1)
        intASCII = Asc(chrInput)	' -- convert Character to Integer
        ' -- shift ASCII code + 1 (if integer = 126 then =32)
        If (intASCII + 1) > 125 Then
            intShifted = 32
        Else
            intShifted = intASCII + 1
        End If
        ' -- convert Integer to ASCII character
        chrEncrypted = Chr(intShifted)	' -- convert Integer to Character
        ' --
        Me.txtEncrypted.Text += chrEncrypted
    Next
End Sub

2.

Option Strict On

Imports System.Drawing.Text
Imports System.Runtime.InteropServices

' Font folder is in app directory

Public Class Form1

    Dim pfc As New PrivateFontCollection()

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))

        Dim AppDataFolderPath As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
        ' Create if necessary a folder for storing a list of Keys and filenames encrypted by those keys by this application
        If My.Computer.FileSystem.DirectoryExists(AppDataFolderPath & "\" & My.Application.Info.AssemblyName) = False Then
            My.Computer.FileSystem.CreateDirectory(AppDataFolderPath & "\" & My.Application.Info.AssemblyName)
        End If
        My.Computer.FileSystem.WriteAllBytes(AppDataFolderPath & "\armyrangers.ttf", My.Resources.armyrangers.ToArray, False)
        My.Computer.FileSystem.WriteAllBytes(AppDataFolderPath & "\galaxyfaraway.ttf", My.Resources.galaxyfaraway.ToArray, False)

        'pfc.AddFontFile("C:\Users\John\Documents\Visual Studio 2012\Fonts - Add custom to app\TestFonts\armyrangers.ttf")
        'pfc.AddFontFile("C:\Users\John\Documents\Visual Studio 2012\Fonts - Add custom to app\TestFonts\galaxyfaraway.ttf")

        pfc.AddFontFile(AppDataFolderPath & "\armyrangers.ttf")
        pfc.AddFontFile(AppDataFolderPath & "\galaxyfaraway.ttf")

        Label1.Font = New Font(pfc.Families(0), 12, FontStyle.Regular)
        Label1.Text = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
        Label2.Font = New Font(pfc.Families(1), 12, FontStyle.Regular)
        Label2.Text = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
        TextBox1.Font = New Font("Book Antiqua", 12)
        TextBox1.Text = "No Way"
        TextBox2.Font = New Font(pfc.Families(1), 12, FontStyle.Regular)
        TextBox2.Text = TextBox1.Text
        ComboBox1.Items.Add("Hello")
        ComboBox1.Items.Add("Whaa's uuup?")
        ComboBox1.Items.Add("Goodbye")
        ComboBox1.Font = New Font(pfc.Families(1), 12, FontStyle.Regular)
        Button1.ForeColor = Color.White
        Button1.Font = New Font(pfc.Families(0), 16, FontStyle.Regular)
        Button1.Text = "Hello"
        Button1.BackgroundImageLayout = ImageLayout.Stretch
        Button1.BackgroundImage = Image.FromFile("C:\Users\John\Desktop\Picture Files\Crossbones BMP.Bmp")
        Button2.ForeColor = Color.White
        Button2.Font = New Font(pfc.Families(1), 12, FontStyle.Regular)
        Button2.Text = "S"
        Button2.BackgroundImageLayout = ImageLayout.Stretch
        Button2.BackgroundImage = Image.FromFile("C:\Users\John\Desktop\Picture Files\Crossbones BMP.Bmp")
    End Sub

End Class

3.

Option Strict On
Public Class Form1

    Dim Reference As New Dictionary(Of String, String)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Reference.Add("H", "G")
        Reference.Add("E", "W")
        Reference.Add("L", "K")
        Reference.Add("O", "I")
        Reference.Add("1", "!")
        Reference.Add("2", "@")
        Reference.Add("3", "#")
        '... and the rest
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        For Each C As String In TextBox1.Text.ToArray
            TextBox2.AppendText(Reference(C))
        Next
    End Sub
End Class

4.

Public Class Form1
    Friend FlowLayoutPanel1 As New FlowLayoutPanel With {.Dock = DockStyle.Fill}
    Friend TextBox1 As New TextBox With {.Width = 270}
    Friend TextBox2 As New TextBox With {.Width = 270}
    Friend TextBox3 As New TextBox With {.Width = 270}
    Friend WithEvents Button1 As New Button With {.Text = "Encode"}
    Friend WithEvents Button2 As New Button With {.Text = "Decode"}

    Private cc As New CharacterCipher(4567)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Controls.Add(FlowLayoutPanel1)
        FlowLayoutPanel1.Controls.Add(TextBox1)
        FlowLayoutPanel1.SetFlowBreak(TextBox1, True)
        FlowLayoutPanel1.Controls.Add(Button1)
        FlowLayoutPanel1.SetFlowBreak(Button1, True)
        FlowLayoutPanel1.Controls.Add(TextBox2)
        FlowLayoutPanel1.SetFlowBreak(TextBox2, True)
        FlowLayoutPanel1.Controls.Add(Button2)
        FlowLayoutPanel1.SetFlowBreak(Button2, True)
        FlowLayoutPanel1.Controls.Add(TextBox3)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox2.Text = cc.Encode(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox3.Text = cc.Decode(TextBox2.Text)
    End Sub
End Class

Public Class CharacterCipher
    Private random As Random
    Private encodeMap As New Dictionary(Of Char, Char)
    Private decodeMap As New Dictionary(Of Char, Char)

    Public Sub New(key As Integer)
        random = New Random(key)
        Regenerate()
    End Sub

    Public Function Decode(value As String) As String
        Dim result As New System.Text.StringBuilder
        For Each c In value
            result.Append(decodeMap(c))
        Next
        Return result.ToString
    End Function

    Public Function Encode(value As String) As String
        Dim result As New System.Text.StringBuilder
        For Each c In value
            result.Append(encodeMap(c))
        Next
        Return result.ToString
    End Function

    Public Function GenerateKey() As Integer
        Dim key As Integer = random.Next
        random = New Random(key)
        Regenerate()
        Return key
    End Function

    Private Sub Regenerate()
        encodeMap.Clear()
        decodeMap.Clear()
        Dim chars As New List(Of Integer)(Enumerable.Range(32, 95))
        For i As Integer = 32 To 126
            Dim index As Integer = random.Next(0, chars.Count)
            encodeMap(Chr(i)) = Chr(chars(index))
            decodeMap(Chr(chars(index))) = Chr(i)
            chars.RemoveAt(index)
        Next
    End Sub
End Class

5.

Public Class Form1
    Dim chars As String = " ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-+=:;" & Chr(34) & "'<,>.?/{}[]~`!@#$%^&*()"
    Dim replc As String = " CFVPNLMKSYBDQZHTAEOUGIRJWX!@#$%^&*()-+=:;" & Chr(34) & "'<,>.?/{_[~`]{1234567890"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.CharacterCasing = CharacterCasing.Upper
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim tmpstr As String = ""
        For Each c As Char In TextBox1.Text.ToCharArray
            Dim ri As Integer = chars.IndexOf(c)
            If ri > -1 Then tmpstr &= replc(ri)
        Next
        TextBox2.Text = tmpstr
    End Sub
End Class

nie którzy tam pomyśleli że chodzi mi o coś innego więc nie które przykłady mogą być na jakiś inny program

 

 

ja bym chciał stworzyć program który zmienia znaki na inne czyli taki własny kod  ASCII ale własny a nie z użyciem  ASCII

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...