Qbasicnews.com

Full Version: I thought this was fun
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok, I do this programming team at my school, and I wanna see how many people can solve this problem. It involves encryption, so you will need to know the ASCII tables to do it. Here it is. Oh, and for an added challenge, try to finish this program in the amount of time it took me, 32 min. Oh, and I do have the code I used, but it's in the school's comp.
Code:
Computer Security Problem:
A major issue with computer security is to store passwords. Passwords are typically encrypted. For this problem, we assume that all passwords are going to be strings that are 4 characters long. They are all encrypted using a form of cryptography known as "shifting and transposition", where we select a positive integer and we use it to shift each character in the password from within it's own catagory. That means that all uppercase reamin uppercase, lowercase remain lowercase and numbers remain numbers, and all other characters do not shift.
So, as an example password:
  bX%7
First, we shift the letters by our cypher. This cypher will be 8:
  jF%5
Then, you will switch the first 2 characters and the last two characters:
  %5jF

Your problem is to read encrypted passwords from a file, decypher them, then output them onto the screen.
The passwords and cypher digit will be given to you in this format:
Line one of file: No meaning (Dummy line)
Line two and three of file: Take the first 2 numbers of the 2nd line (will always be numbers) and the last 2 numbers of the 3rd line (will always be numbers) and add them together to make the cypher digit
Line four of file: No meaning (Dummy line)
Line five of file: The number of strings to decode (Line 5 will be a number that will represent the number of strings, ex. 0005 means 5 passwords and 0500 means 500 passwords)
Line 6+ of file: Passwords
There is no minimum or maximum length of the file, and people should be able to specify the file name at runtime. Code has no minimum or maximum limber of lines. It can only use pure qb commands though. Good luck. I will give you a sample file.
Code:
"abcd"
"0245"
"5603"
"0896"
"0005"
"7777"
"6923"
"6#&5"
"cdeb"
"YfAg"
This should create an output of:
Code:
2222
7814
&01#
zwxy
VbTa
Good Luck
'Take the first 2 numbers of the 2nd line (will always be numbers)'
they dont look like numbers
Whacha mean?
"0245"

Thats very much a number
Quote:Whacha mean?
"0245"

Thats very much a number

lol misunderstanding

just one more quetion ( i hope)

if everything after line 6 and more is a password
Code:
"7777"
"6923"
"6#&5"
"YfAg"

then how come there are 5 outputs?
Code:
2222
7814
&01#
zwxy
VbTa
Code:
CLS
INPUT "What is the file to be deciphered? ", cur.file$
OPEN cur.file$ FOR INPUT AS #1
INPUT #1, bla$: INPUT #1, bla1$: INPUT #1, bla2$
shifter% = VAL(MID$(bla1$, 1, 1)) + VAL(MID$(bla1$, 2, 1))
shifter% = shifter% + VAL(MID$(bla2$, 3, 1)) + VAL(MID$(bla2$, 4, 1))
INPUT #1, bla$: INPUT #1, bla$
CLS
DO
INPUT #1, pass$
pass$ = MID$(pass$, 3, 4) + MID$(pass$, 1, 2)
FOR i% = 1 TO 4
n% = ASC(MID$(pass$, i%, 1))
SELECT CASE n%
CASE 65 TO 90: n% = n% - shifter%
1 IF n% < 65 THEN n% = n% + 26: GOTO 1
CASE 97 TO 122: n% = n% - shifter%
2 IF n% < 97 THEN n% = n% + 26: GOTO 2
END SELECT
MID$(pass$, i%, 1) = CHR$(n%)
NEXT i%
PRINT pass$
IF EOF(1) THEN EXIT DO
LOOP
Looks wrong. Make sure that Characters like lowercase and uppercase and symbols remain seperate. ABC# shifted by 1 is BCD# and ZzZz shifted by 1 is AaAa.
Oh. I didn't see the last part of the instructions. I fixed it. . .