Click to See Complete Forum and Search --> : modulus reversal and counting integers


conyers
Feb 1st, 2001, 10:46 AM
How do you reverse the calculation imposed by a modulus symbol? ie if you encrypt by (number + 7) Mod 10 in an encryption program, how could one write a separate decryption program that accepts an encrypted number and decrypts it back to its original state?

Additionally - how could one code a program that reads in a 1-5 digit integer in a singular textbox then total and print the amount of number 7's typed into the text box?

please help

F

metalcrib@hotmail.com

Guv
Feb 1st, 2001, 03:37 PM
Put data from text box into a string and use Mid Function in a For loop to examine the individual digits.

It is not clear what you mean by (Number + 7) Mod ten. Is the Mod function applied to each digit of a long decimal number? Is it applied to byte data?

kedaman
Feb 2nd, 2001, 07:33 AM
'limits textbox to 5 characters
Private Sub Text1_Change()
If Len(Text1) > 5 Then Text1 = Left(Text1, 5)
End Sub

'count 7'ns in a tetbox
a=instr(text1,"7")
Do while a
count=count+1
a=instr(a+1,text1,"7")
loop

Using mod for a encryption isn't a too bright idea, you have to be sure to have an individual result for each number, otherways you can't decrypt it, if you pass a number trough (number+7) mod 10 number has to be a integer from X to X+9.