Encrypting and Decryption of a string. - vba

I was given a task to encrypt a string, but I must create my own encryption techniques.
I have an idea of how to do it. I can associate each value in a string with a number, like so:
A = 0
B = 1
...
And then I want to substitute characters for digits in the tens and higher: if I enter the string "DOG" it must display
3.46 // . is 1 and .. is 2
// .4 is 14
I would like hear your ideas.
I was given a visual basic form to work on. I can enter a string; that is fine.
Input = txtInputString.Text
But I also have to decrypt a string. To show I want to decrypt the string I have to have
string, false
, the false showing that i want to decrypt the string. How do i do this?

Encryption and decryption of simple English text is fairly quite forward if you use a simple method such as Ceasar Cipher.
However you have to determine how you are going to represent all of the symbols in the language. This would include not only letters but digits and spaces and maybe punctuation as well.
The standard ASCII character set has most of what you might need for English the question is whether you want to simplify your alphabet by restricting your symbols to only upper case letters, digits, and a space. Human beings can usually read text, especially short text even if it does not have punctuation.
The approach for a simple cipher would be to have a table of the symbols in your alphabet (the upper case letters, digits zero through nine, and a space character). Next rearrange the table so that it is not in sorted order.
When doing an encrypt you would take each character, look it up in the table and determine a two digit offset within the table. This two digit number would be the encryption symbol for that character and is what you would write out as part of the string of encryption.
When doing a decrypt you would take each two digit pair and use that as an offset into the table, find the character at that location in the table, and the write the character from the table out as part of the string of decryption.
Your encrypted string would be a series of two digit pairs all strung together as one long number.
For your form, I would expect to have two text entry groups each with a button, a text entry field, and a text display field. The first group would be for the text to encrypt and that button you would press to perform an encrypt once the text is entered. The encryption text would display in the field below the text entry field.
The second group would be the text to decrypt and that button you would press to perform a decrypt.

Related

How to avoid plus sign to create a line feed in a rdlc textbox

I need to print an encrypted string as is in a rdlc report. My problem is if the string contain a plus sign it creates a new line in the Textbox. How to avoid this?
Encryption produces output that is binary and contains many bytes that have no displayable representation.
Because of this if encrypted data needs to be displayed it is generally either Base64 (best for computers) or hexadecimal (best for people) encoded.
It seems that you may have base64 encoded encrypted data and that is generally composed of the upper and lowercase characters, the 10 digits, "+", "/" and "=". You can not delete these and expect to recover the encrypted data.
If these characters present a problem they can be many times be escaped in some manor or another encoding can be chosen such as hexadecimal or an alternate Base64 character set, see Base64. If you choose an alternate Base64 character set interoperability will most likely be impaired.
Note: More information would produce a better answer.
I had to replace the "+" with "÷".
Users don't notice is it since the PDF is just a visual representation of the CFDI, I haven't had any issues with it.

Converting symbols from outside of alphabet caused by copying text in different encoding

In my database I should only have data written using Polish alphabet but sometimes there are symbols not included in Polish alphabet (words copied from source with different encoding) that correspond to Polish letters in another encoding. Is it possible to somehow convert symbols outside of Polish alphabet to corresponding letters?
The only solution I figured is to manually find and replace those characters but maybe you have better solution to my problem.
Question concerns Oracle SQL Language.
I don't have database in front of me but as I remember correctly the example could look like this - two rows from my db:
ŚWIAT
ÚWIAT
and what I need is to convert Ú that doesn't belong to Polish alphabet to Ś.
You can try this. Experiment with it first to see if it works.
If I want to change every occurrence of the letter z with a j in a string, I would use the translate function: translate(text_string, 'z', 'j'). I don't have to use the letters z and j; instead, I can write translate(text_string, chr(122), chr(106) - to find out the character code, I use select ascii('z') from dual;. For example:
SQL> select translate('banzo', chr(122), chr(106)) from dual;
TRANS
-----
banjo
This changes every occurrence of z to j in text_string.
Now, you will have to find the code for the characters you want to change (both the "from" and the "to" characters) in your character set - it should be your session character set, not the database character set. (At least I think this is correct; experiment with it or read the documentation for CHR and perhaps for TRANSLATE - CHR returns the character code in the DATABASE character set unless you indicate otherwise, while I believe TRANSLATE uses the session character set.)
The function ascii may or may not work for non-ASCII characters, but if you google the name of your character set, you should find a character set table that will show you the codes for all the letters available in that character set.
Then, if this works, you can do the translation in one shot - translate(text_string, 'abcd', 'qrst') will change every 'a' to a 'q', every 'b' to an 'r' etc. And with chr(...), instead of 'abcd' you can write chr(97) || chr(98) || chr(99) || chr(100).

Regex extracting numbers & letters - Visual Basic

And again, I am having issues with regex.
Well basically I want to extract info from a website, and get it in a textbox.
what I want to be extracted
So as you can see, the part what says 11111 must be enabled to also extract letters instead of only numbers.
I use this code:
Dim mcol As MatchCollection = Regex.Matches(source, "/player/\d+"">(.+)</a>")
How can I make it to extract not only numbers, but both.
So it will be enable to extract a MD5 hash?
Kind regards
/\w+/i it will match any alphanumeric character with case insensitive modifier. As we know that MD5 is 32 digit hexadecimal number so the above regex may be useful in your case.

Finding the ascii value for shift-in shift-out in sql?

I've some records which are really messed up.
My team lead told me to find out the position of characters with ascii value 14 and 15.
I've a query
SELECT CHARINDEX(CHAR(14),X_CUSTOMER_COMMENTS)
FROM vp_service_requests;
SELECT CHARINDEX(CHAR(15),X_CUSTOMER_COMMENTS)
FROM vp_service_requests;
which returns 0 because i wasn't able to find char with 14 and 15 ascii value after google
search i found 14 and 15 ascii value are for shift in and shift out
how this represents on keyboard so i can try for it with CHAR(14) function.
As a holdover from the old DOS days, Windows still allows you to enter certain old ASCII keys from the keyboard by pressing and holding the ALT key, followed by the three-digit code you wish to enter (from the 10-key pad, not the numeric row atop the keyboard), eg for 14, type ALT-014.
However, some of the lower-level codes are inherited from old terminal functions, eg ASCII 7 is a bell, 8 is a backspace, eg, and rather that typing a character, they cause the cursor to behave a certain way or induce an application to respond in a defined manner. You can embed a CHAR(XX) value for testing simply by concatenating the value into a string and INSERTing it into your test table.
It should be Ctrl-N and Ctrl-O although I doubt this will help.
Try loading the records into a good editor and look at them in HEX. Weird characters should stick out like a sore thumb

How can I write special character in VB code

I have a Sql statament using special character (ex: ('), (/), (&)) and I don't know how to write them in my VB.NET code. Please help me. Thanks.
Find out the Unicode code point for the character (from http://www.unicode.org) and then use ChrW to convert from the code point to the character. (To put this in another string, use concatenation. I'm somewhat surprised that VB doesn't have an escape sequence, but there we go.)
For example, for the Euro sign (U+20AC) you'd write:
Dim euro as Char = ChrW(&H20AC)
The advantage of this over putting the character directly into source code is that your source code stays "just pure ASCII" - which means you won't have any strange issues with any other program trying to read it, diff it, etc. The disadvantage is that it's harder to see the symbol in the code, of course.
The most common way seems to be to append a character of the form Chr(34)... 34 represents a double quote character. The character codes can be found from the windows program "charmap"... just windows/Run... and type charmap
If you are passing strings to be processed as SQL statement try doubling the characters for example.
"SELECT * FROM MyRecords WHERE MyRecords.MyKeyField = ""With a "" Quote"" "
The '' double works with the other special characters as well.
The ' character can be doubled up to allow it into a string e.g
lSQLSTatement = "Select * from temp where name = 'fred''s'"
Will search for all records where name = fred's
Three points:
1) The example characters you've given are not special characters. They're directly available on your keyboard. Just press the corresponding key.
2) To type characters that don't have a corresponding key on the keyboard, use this:
Alt + (the ASCII code number of the special character)
For example, to type ¿, press Alt and key in 168, which is the ASCII code for that special character.
You can use this method to type a special character in practically any program not just a VB.Net text editor.
3) What you probably looking for is what is called 'escaping' characters in a string. In your SQL query string, just place a \ before each of those characters. That should do.
Chr() is probably the most popular.
ChrW() can be used if you want to generate unicode characters
The ControlChars class contains some special and 'invisible' characters, plus the quote - for example, ControlChars.Quote