473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

need help with the chrW function and handling invalid inputs

At the moment im working on an encryption program, just to prove something to myself. At the moment I have a problem, when I run the program it will drop a few characters and return wrong characters, here is the encrypter code.

Expand|Select|Wrap|Line Numbers
  1.         Dim x As Int64
  2.         Dim y As Int64
  3.         Dim z As Int64
  4.         Dim chrpos As Int64
  5.         Dim chrcode As Int64
  6.         Dim str As String
  7.         Dim Buffstr As String
  8.         Buffstr = ""
  9.         str = TBX1.Text
  10.         For z = 0 To 10
  11.             Buffstr = ""
  12.             For x = 0 To str.Length - 1
  13.                 For y = -32768 To 65535
  14.                     If str.Chars(x) = ChrW(y) Then
  15.                         chrcode = y
  16.                         chrpos = x
  17.                     End If
  18.                 Next
  19.                 chrcode = chrcode + ((chrpos * chrpos))
  20.                 While chrcode > 65535
  21.                     chrcode -= 65535
  22.                 End While
  23.                 While chrcode <= -32768
  24.                     chrcode += 32768
  25.                 End While
  26.                 Buffstr = Buffstr & ChrW(chrcode)
  27.             Next
  28.             str = Buffstr
  29.         Next
  30.         tbx2.Text = str
  31.  
notes:
> tbx1 and 2 are textboxes for input/output

> the difference between the encryption and decryption code is that the decryption is the addition the square of the position of the characters and the encryption is the subraction of the sqaure of the position of the characters

>when I run the code above and encrypt 195 1's then decrypt the output it rerurns

11111111111111111111111111111111111111111111111111 11111111111111111111111111112222222222222222222222 22222222223333333333333333333333334444444444444444 44444555555555555555555666666666666666667耷77耷

the output should be 195 1's but it is as above

in advance thank you for the help
May 9 '10 #1
2 1452
tlhintoq
3,525 Expert 2GB
Original Poster: I have xxx, then do yyy then zzz happens. Here's my code ...
Ok. You know what you have.
What you don't have is a question. Nobody here knows why you posted this since you haven't asked anything, or exception or description of any error messages you are getting. You haven't described anything that is broken, or any 'expected' results versus 'actual' results.
I recommend you read the FAQ about How to ask a good question so the volunteers will be able to help
May 9 '10 #2
@tlhintoq
I have ammended my question and added the actual and expected results. Tahnkyou for thhe pointers
May 10 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Edward Singleton | last post by:
I am currently developing a web app using WSAD 5.1 and DB2 V7.2.8. I understand there is a myriad of database errors related to obtaining valid connections that are mapped directly to...
5
by: Jim | last post by:
Need help with aggregate function...for each unique product, I need the provider with the cheapest cost factor Here't the table (Table1) ID product provider factor 1 123456 abc...
1
by: Srinivasa Ra via .NET 247 | last post by:
(Type your message here) I am writing an application that does lot of read/write's withcomputer's serial port. The application as a whole is workingfine. Current Approach: I have a Timer that...
3
by: mydejamail | last post by:
Is there a major flaw with PHPs variable handling? I am writing some PHP scripts and the variables seem to be all over the place. Eg in one instance, I am counting the number of times a for loop...
2
by: Adam | last post by:
I have an unfortunate case where a single class wants to derive from two existing classes: struct A { virtual long fun() = 0; }; struct B { virtual bool fun() = 0; }; struct Unfortunate :...
7
by: lovecreatesbea... | last post by:
K&R 2, sec. 5.11 says that no need to precede function and array names with address-of operators &, why?
11
by: Vijaykumar Dave | last post by:
Is there anyone have calculator program with memory function ? I need it for submission of assignment. Vijaykumar Dave
10
by: joestevens232 | last post by:
Ok everything is good...I read in all my grades into each of the different arrays that they need to go in. Now Im trying to write a function that takes the grades and computes the average on a...
4
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark...
4
by: =?Utf-8?B?UGF1bA==?= | last post by:
Just wondering if there is a way to cause a post back with a javascript function? Thanks. -- Paul G Software engineer.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.