Hey,
i need some guidance.Im working on a project in vba(in excel).I am trying to create a shift cipher(example dog would be fqi)
i want the input to be in an input box(have that part) with the text to be shifted and amount that it will be shifted.The output will be in excel in a 20 column by n row array.I made a function to remove all non alphabetic lower case characters.This is what i have so far(theres a lot of things I just need help finishing and putting it all together).
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
<img src="/cgi-bin/mimetex.cgi?'Ask for dimensions of array and output numbers in arraySub NumberArray() 'this puts up input boxes and then stores the inputs to variables NumRows = InputBox("Input the number of rows.") NumColumns = InputBox("Input the number of columns.") For i = 1 To NumRows ' completes 1 row at a time For j = 1 To NumColumns 'goes through each column 1 at time Cells(i, j).Value = j + (i - 1) * NumColumns Next j Next iEnd Sub 'change all letters to lowercase'remove all non alphabetic charactersFunction Remove(x) tempText = LCase(x) 'change all letters to lowercase For i = 1 To Len(x) 'len is number of characters in the script If Asc(Mid(tempText, i, 1)) >= 97 And Asc(Mid(tempText, i, 1)) <= 122 Then '97 is ascii a and 122 is ascii z tempOutput = tempOutput & (Mid(tempText, i, 1)) End If Next i Remove = tempOutput 'outputs the textEnd Function Function ShiftCipher(text, shiftamount) shiftamount = InputBox("Input how many numbers to shift by") Select Case letter Case "a" letter = Chr(97 + shiftamount) Case "b" letter = Chr(98 + shiftamount) Case "c" letter = Chr(99 + shiftamount) Case "d" letter = Chr(100 + shiftamount) Case "e" letter = Chr(101 + shiftamount) Case "f" letter = Chr(102 + shiftamount) Case "g" letter = Chr(103 + shiftamount) Case "h" letter = Chr(104 + shiftamount) Case "i" letter = Chr(105 + shiftamount) Case "j" letter = Chr(106 + shiftamount) Case "k" letter = Chr(107 + shiftamount) Case "l" letter = Chr(108 + shiftamount) Case "m" letter = Chr(109 + shiftamount) Case "n" letter = Chr(110 + shiftamount) Case "o" letter = Chr(111 + shiftamount) Case "p" letter = Chr(112 + shiftamount) Case "q" letter = Chr(113 + shiftamount) Case "r" letter = Chr(114 + shiftamount) Case "s" letter = Chr(115 + shiftamount) Case "t" letter = Chr(116 + shiftamount) Case "u" letter = Chr(117 + shiftamount) Case "v" letter = Chr(118 + shiftamount) Case "w" letter = Chr(119 + shiftamount) Case "x" letter = Chr(120 + shiftamount) Case "y" letter = Chr(121 + shiftamount) Case "z" letter = Chr(122 + shiftamount) End Select ShiftCipher = text + shiftamount End Function" alt="'Ask for dimensions of array and output numbers in arraySub NumberArray() 'this puts up input boxes and then stores the inputs to variables NumRows = InputBox("Input the number of rows.") NumColumns = InputBox("Input the number of columns.") For i = 1 To NumRows ' completes 1 row at a time For j = 1 To NumColumns 'goes through each column 1 at time Cells(i, j).Value = j + (i - 1) * NumColumns Next j Next iEnd Sub 'change all letters to lowercase'remove all non alphabetic charactersFunction Remove(x) tempText = LCase(x) 'change all letters to lowercase For i = 1 To Len(x) 'len is number of characters in the script If Asc(Mid(tempText, i, 1)) >= 97 And Asc(Mid(tempText, i, 1)) <= 122 Then '97 is ascii a and 122 is ascii z tempOutput = tempOutput & (Mid(tempText, i, 1)) End If Next i Remove = tempOutput 'outputs the textEnd Function Function ShiftCipher(text, shiftamount) shiftamount = InputBox("Input how many numbers to shift by") Select Case letter Case "a" letter = Chr(97 + shiftamount) Case "b" letter = Chr(98 + shiftamount) Case "c" letter = Chr(99 + shiftamount) Case "d" letter = Chr(100 + shiftamount) Case "e" letter = Chr(101 + shiftamount) Case "f" letter = Chr(102 + shiftamount) Case "g" letter = Chr(103 + shiftamount) Case "h" letter = Chr(104 + shiftamount) Case "i" letter = Chr(105 + shiftamount) Case "j" letter = Chr(106 + shiftamount) Case "k" letter = Chr(107 + shiftamount) Case "l" letter = Chr(108 + shiftamount) Case "m" letter = Chr(109 + shiftamount) Case "n" letter = Chr(110 + shiftamount) Case "o" letter = Chr(111 + shiftamount) Case "p" letter = Chr(112 + shiftamount) Case "q" letter = Chr(113 + shiftamount) Case "r" letter = Chr(114 + shiftamount) Case "s" letter = Chr(115 + shiftamount) Case "t" letter = Chr(116 + shiftamount) Case "u" letter = Chr(117 + shiftamount) Case "v" letter = Chr(118 + shiftamount) Case "w" letter = Chr(119 + shiftamount) Case "x" letter = Chr(120 + shiftamount) Case "y" letter = Chr(121 + shiftamount) Case "z" letter = Chr(122 + shiftamount) End Select ShiftCipher = text + shiftamount End Function" border="0" /><img src="/cgi-bin/mimetex.cgi?'Ask for dimensions of array and output numbers in array
Sub NumberArray()
'this puts up input boxes and then stores the inputs to variables
NumRows = InputBox("Input the number of rows.")
NumColumns = InputBox("Input the number of columns.")
For i = 1 To NumRows ' completes 1 row at a time
For j = 1 To NumColumns 'goes through each column 1 at time
Cells(i, j).Value = j + (i - 1) * NumColumns
Next j
Next i
End Sub
'change all letters to lowercase
'remove all non alphabetic characters
Function Remove(x)
tempText = LCase(x) 'change all letters to lowercase
For i = 1 To Len(x) 'len is number of characters in the script
If Asc(Mid(tempText, i, 1)) >= 97 And Asc(Mid(tempText, i, 1)) <= 122 Then '97 is ascii a and 122 is ascii z
tempOutput = tempOutput & (Mid(tempText, i, 1))
End If
Next i
Remove = tempOutput 'outputs the text
End Function
Function ShiftCipher(text, shiftamount)
shiftamount = InputBox("Input how many numbers to shift by")
Select Case letter
Case "a"
letter = Chr(97 + shiftamount)
Case "b"
letter = Chr(98 + shiftamount)
Case "c"
letter = Chr(99 + shiftamount)
Case "d"
letter = Chr(100 + shiftamount)
Case "e"
letter = Chr(101 + shiftamount)
Case "f"
letter = Chr(102 + shiftamount)
Case "g"
letter = Chr(103 + shiftamount)
Case "h"
letter = Chr(104 + shiftamount)
Case "i"
letter = Chr(105 + shiftamount)
Case "j"
letter = Chr(106 + shiftamount)
Case "k"
letter = Chr(107 + shiftamount)
Case "l"
letter = Chr(108 + shiftamount)
Case "m"
letter = Chr(109 + shiftamount)
Case "n"
letter = Chr(110 + shiftamount)
Case "o"
letter = Chr(111 + shiftamount)
Case "p"
letter = Chr(112 + shiftamount)
Case "q"
letter = Chr(113 + shiftamount)
Case "r"
letter = Chr(114 + shiftamount)
Case "s"
letter = Chr(115 + shiftamount)
Case "t"
letter = Chr(116 + shiftamount)
Case "u"
letter = Chr(117 + shiftamount)
Case "v"
letter = Chr(118 + shiftamount)
Case "w"
letter = Chr(119 + shiftamount)
Case "x"
letter = Chr(120 + shiftamount)
Case "y"
letter = Chr(121 + shiftamount)
Case "z"
letter = Chr(122 + shiftamount)
End Select
ShiftCipher = text + shiftamount
End Function" alt="'Ask for dimensions of array and output numbers in array
Sub NumberArray()
'this puts up input boxes and then stores the inputs to variables
NumRows = InputBox("Input the number of rows.")
NumColumns = InputBox("Input the number of columns.")
For i = 1 To NumRows ' completes 1 row at a time
For j = 1 To NumColumns 'goes through each column 1 at time
Cells(i, j).Value = j + (i - 1) * NumColumns
Next j
Next i
End Sub
'change all letters to lowercase
'remove all non alphabetic characters
Function Remove(x)
tempText = LCase(x) 'change all letters to lowercase
For i = 1 To Len(x) 'len is number of characters in the script
If Asc(Mid(tempText, i, 1)) >= 97 And Asc(Mid(tempText, i, 1)) <= 122 Then '97 is ascii a and 122 is ascii z
tempOutput = tempOutput & (Mid(tempText, i, 1))
End If
Next i
Remove = tempOutput 'outputs the text
End Function
Function ShiftCipher(text, shiftamount)
shiftamount = InputBox("Input how many numbers to shift by")
Select Case letter
Case "a"
letter = Chr(97 + shiftamount)
Case "b"
letter = Chr(98 + shiftamount)
Case "c"
letter = Chr(99 + shiftamount)
Case "d"
letter = Chr(100 + shiftamount)
Case "e"
letter = Chr(101 + shiftamount)
Case "f"
letter = Chr(102 + shiftamount)
Case "g"
letter = Chr(103 + shiftamount)
Case "h"
letter = Chr(104 + shiftamount)
Case "i"
letter = Chr(105 + shiftamount)
Case "j"
letter = Chr(106 + shiftamount)
Case "k"
letter = Chr(107 + shiftamount)
Case "l"
letter = Chr(108 + shiftamount)
Case "m"
letter = Chr(109 + shiftamount)
Case "n"
letter = Chr(110 + shiftamount)
Case "o"
letter = Chr(111 + shiftamount)
Case "p"
letter = Chr(112 + shiftamount)
Case "q"
letter = Chr(113 + shiftamount)
Case "r"
letter = Chr(114 + shiftamount)
Case "s"
letter = Chr(115 + shiftamount)
Case "t"
letter = Chr(116 + shiftamount)
Case "u"
letter = Chr(117 + shiftamount)
Case "v"
letter = Chr(118 + shiftamount)
Case "w"
letter = Chr(119 + shiftamount)
Case "x"
letter = Chr(120 + shiftamount)
Case "y"
letter = Chr(121 + shiftamount)
Case "z"
letter = Chr(122 + shiftamount)
End Select
ShiftCipher = text + shiftamount
End Function" border="0" />