|
-
Aug 9th, 2000, 12:29 PM
#1
Thread Starter
Lively Member
Hi everyone!
I have a pair of questions for you. Actually i'm working to
a program that, given some 8-bit random generated numbers
in binary, for example, 10001011, it converts it to
hexadecimal value and then to ascii chars.
1) The problem is that sometimes random-generated codes
goes under 31-decimal and Chr has to use 2 bytes to
represent them. The problem is solved (?) by using ChrB or
ChrB$ but, as i try to substitute them to Chr it does work
no more, since it does not give back anything. Do you have
any idea for this?
2) Do you know ho to implement something to make cursor goes
to the lower line when there are no more spaces (as in
notepad, "Return automatilly", in Edit menu, i think...
don't know in English...)
3) Why does my Rnd() function always give back tha same
numbers? When the programis run, the sequence of random
number is always the same every time... Does this have
something to do with Randomize?
Thanks a lot for any help...
-
Aug 9th, 2000, 12:43 PM
#2
Frenzied Member
Answer to number 3. Your random values will only be as random as your seed. Using the same seed all the time will generate the same sequence of "random" numbers.
-
Aug 9th, 2000, 12:54 PM
#3
For qustion 2, are you referring to WordWrap? If so, then set the ScrollBars property of the TextBox to 0-None or 2-Vertical.
-
Aug 9th, 2000, 12:57 PM
#4
Thread Starter
Lively Member
Hi JHausmann,
So how can i random a number indipendently from the seed...
i need the program to generate different numbers every time...
Thanks
-
Aug 9th, 2000, 01:00 PM
#5
Frenzied Member
Base your seed on the system time.
-
Aug 9th, 2000, 01:01 PM
#6
Thread Starter
Lively Member
Hi Megatron,
Yes! I was referring to that... That's so simple! ;-) I was
getting crazy withb this! Thanks!
By the way, do you have any idea about the first question?
Is this normal that VB gives back 2 chars when the Ascii
code is before the 31-decimal?
-
Aug 9th, 2000, 01:05 PM
#7
For #1: Can you please rephrase it? I do not quite understand.
For #3, use the Randomize statement.
Code:
Randomize
Num = Int(Rnd * 100) + 1
Print Num
-
Aug 9th, 2000, 01:06 PM
#8
Thread Starter
Lively Member
Ehm... Eheh! I really do not know how to that... can you give me a pice of code? Thanks again
-
Aug 9th, 2000, 01:18 PM
#9
Thread Starter
Lively Member
Ok Megatron,
the question is the following: my program gets from a
procedure a 8-bit binary value. Let's suppose, for example,
10010100. Now my program has to convert this number to
decimal, in this case 148, and then to the corresponding
ASCII character, in this case "o with dieresis". The
problem is that when i get characters from decimal values,
sometimes the Chr function gives me back two Ascii
characters instead of one... This seems to happen when i
get ASCII characters from decimal values that are lower
than 31. Maybe because these are special characters and
need two characters to be represented? In fact, API says
that some ASCII values will be represented with two simbol,
as, for istance ENTER key will be represented with |&...
for example. To solve the problem API suggest to use ChrB
or ChrB$, that gives back only a byte (i.e., only one
simbol)... But when i substitute in my program ChrB to Chr,
the program does no more work: for every binary value, it
gives back a empty string.
Hope you could help me... Thanks a lot.
PS Thanks also for Randomize tip.
-
Aug 10th, 2000, 02:04 AM
#10
Thread Starter
Lively Member
No idea... It's impossible!
-
Aug 10th, 2000, 11:44 AM
#11
Answers to all 3!
#1: The ascii values under 31 are unprintable, eg. Backspace, Return, Beep... Those are not characters of any type, and thus they don't appear normally.
#2: Set the scrollbars of the textbox to either None or Vetical, and the MultiLine property to True.
#3: Use this:
Randomize Timer
Temp = Rnd
Debug.Print Temp
Hope this helps.
-
Aug 10th, 2000, 12:02 PM
#12
Solution to #1
Try this:
Code:
'Dec is your decimal value
Dim sTemp As String
If Dec < 32 Then
sTemp = ChrB(Dec)
Else
sTemp = Chr(Dec)
End If
Try it. I didn't try it on my computer yet.
-
Aug 10th, 2000, 01:16 PM
#13
Thread Starter
Lively Member
GREAT!
Wow! You are great! This will solve me a lot of problem
but... Ok let me explain.
I am making a Vernam cryptographic program. This kind of
cifration is theorically perfect and is at most unbrekable.
It works this way: you get a phrase for input, for
istance "hi", it is converted to binary,
i.e. "01101000 01101001"... Then the program generates a
binary number as long as source binary string, for
istance "11100000 00000111" and bitwise-Xor this one with
the source:
source: "hi" 01101000 01101001
generated key: "(ascii 224 + ascii 3)" 11100000 00000011
cripted text: "(ascii 144 + ascii 116)"10001000 01101010
While i can check for random-generated key not to have
characters beyond the 31, i cannot do this for cripted text.
Sometimes characters beyond 31 appears in the cripted text,
thus making the program not to work correctly.
I really cannot figure out a way to solve this problem. I
have also to use Terminal font because it is the only one
which can show *ALL* characters in the ASCII table. Others,
like MS Sans Serif do represent "|" for a lot of characters,
... But i think that the difference between two different
characters that are represented with the same symbol ("|")
is anyway present in the lower hexadecimal level...
Well.
Can you figure out how to solve this problem?
Thanks a lot.
-
Aug 10th, 2000, 01:26 PM
#14
Chars under 31
Even though some characters look the same,
they're value is not the same.
If you read the Asc() value of two different chars that
look the same you will get two different values.
And thus the encrypter\decrypter will not have problems
with it.
-
Aug 10th, 2000, 01:28 PM
#15
About the first problem you mentioned in your first post,
I need to see the code in order to try to solve the problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|