 |
Das deutsche QBasic- und FreeBASIC-Forum Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
DarkLord
Anmeldungsdatum: 26.03.2005 Beiträge: 70 Wohnort: Rhade^^ oben bei muddi
|
Verfasst am: 26.03.2005, 19:49 Titel: QBasic ; ein paar fragen |
|
|
PRINT "So, da ich leider mit der suchfunktion nichts gefunden habe.
PRINT "muss ich euch leider auf die nerven gehen *g*"
' Das ist nur zur belustigung gedacht^^
Ich habe ein paar Probleme mit meinen Programmen...
1. Es soll eine Taste abgefragt werden (jede belibige). Wie geht dass, das diese Taste danach in " in einer Textdatei steht? Außerdem soll es ungefähr so aussehen (in der Textdatei)
vorgegebener Text "Die Taste die man gedrückt hat" "ein Text aus einer Variablen"
das mit dem vorherigen vogegeben Text habe ich hinbekommen, aber wie mache ich das andere (Besonders dass, das der Text in der Datei in " steht?
Muss man dafür die Tasten in Variablen schreiben um sie später so in die Datei zu bekommen oder wie macht man so was?
2. Gibt es einbe Alternative zu dem Befehl "sleep", damit man eine Pause machen kann um den Benutzer den Text lesen zu lassen, denn wenn ich "sleep" benutze steht dann schon in der nächsten "input" eingabe die eingegebene Zahl oder der eingegebene Buchstabe.
3. Kann man von einer festgelegten String-Variablen einen Wert abziehen und wenn ja wie? Ich weiß das man einen dazuzählen kann aber abziehen?
4. Kann man eine String-Variable die man in einer Datei geschpeichert hat, (einfach) verschlüsseln ? Wenn ja wie macht man so was?
5. Wie kann man den fertigen Programmen ein Icon geben (also, der exe datei) ?
mfg. DarkLord
PS: ich weiß das die fragen ein bisschen blöd gestellt sind |
|
Nach oben |
|
 |
Sebastian Administrator

Anmeldungsdatum: 10.09.2004 Beiträge: 5969 Wohnort: Deutschland
|
Verfasst am: 26.03.2005, 20:05 Titel: |
|
|
Hallo.
1.
Code: | INPUT "Text? ", Variable$
OPEN "DATEI.TXT" FOR OUTPUT AS #1
PRINT #1, CHR$(34); "Vorgegeben"; CHR$(34); " "; CHR$(34); Variable$; CHR$(34)
CLOSE #1 |
2. Zwischen SLEEP und dem nächsten INPUT/INKEY den Tastaturpuffer leeren (=> siehe MonsterFAQ).
3. Strings enthalten Zeichenketten. Rechnen kann man nur mit Zahlvariablen wie Integern usw.
4. => Siehe Downloadbereich von www.qbasic.de. Dort gibt es die QB-Wundertüte mit über 1000 Programmen, die sich teilweise auch damit beschäftigen. Am einfachsten ist sicher eine XOR-Verschlüsselung.
Ein Beispiel:
Code: | '===========================================================================
' Subject: XOR ENCRYPTION/DECRYPTION Date: 08-10-96 (12:55)
' Author: Jonathan Leger Code: QB, QBasic, PDS
' Origin: leger@mail.dtx.net Packet: BINARY.ABC
'===========================================================================
'(*** XOR.BAS ***)
'(*************************************************************************)
'(*** This is a small demonstration of the XOR encryption/decryption ***)
'(*** method that will encrypt this file (assuming the name is XOR.BAS) ***)
'(*** and put it in the file XOR.XOR. If you want it to decrypt the ***)
'(*** XOR.XOR file once it's been encrypted, merely change the FILE$ ***)
'(*** to XOR.XOR and the OUTPUT$ to XOR.BAS (or whatever). The key ***)
'(*** we will be using is 15. You can change that for your purposes, ***)
'(*** but the key must be a value from 0 to 255. ***)
'(*************************************************************************)
'(*** This method of encryption is not very secure, since it can be ***)
'(*** broken easily by the brute force method (though it used to be a ***)
'(*** very popular form of encryption). However, for most purposes, ***)
'(*** such as game high scores or passwords, etc, it serves quite well, ***)
'(*** since the person has no way to know that the file was encrypted ***)
'(*** using this method, and most people wouldn't think to try and ***)
'(*** decrypt it themselves anyway. ***)
'(*************************************************************************)
'(*** The File.XOR function returns a FALSE value (0) if the input file ***)
'(*** (FILE$) does ***) not exist, otherwise it returns TRUE (-1). ***)
'(*************************************************************************)
DECLARE FUNCTION File.XOR% (FILE$, output$, ekey%, sbarx%, sbary%, sbarlen%)
SCREEN 0
WIDTH 80, 25
COLOR 7, 0
CLS
FILE$ = "xor.bas" '(*** We'll encrypt this file... ***)
output$ = "xor.xor" '(*** ...and put the results here. ***)
ekey% = 15 '(*** Our encryption key will be 15. ***)
LOCATE 1, 1
PRINT "Using XOR method of encryption/decription on " + UCASE$(FILE$) + "..."
'(*** Use a status bar for the encryption. ***)
COLOR 15, 1
ErrVal = File.XOR%(FILE$, output$, ekey%, 1, 2, 40)
IF ErrVal THEN '(*** No errors! ***)
LOCATE 1, 1: COLOR 7, 0
PRINT STRING$(80, " ");
LOCATE 1, 1
PRINT "Success! Results in file (" + UCASE$(output$) + ")."
ELSE
'(*** The file didn't exist! ***)
LOCATE 1, 1: COLOR 7, 0
PRINT STRING$(80, " ");
LOCATE 1, 1
PRINT "Input file ("; UCASE$(FILE$); ") does not exist."
END IF
DEFINT A-Z
'(*** File.XOR () ****)
'(*** ----------- ****)
'(*** Thie function will take a file (INPUT$) and XOR each byte with ***)
'(*** the given encryption key (EKEY), puting the results into a file ***)
'(*** (OUTPUT$). If you want a status bar showing progress, pass the ***)
'(*** x and y location of the status bar on-screen (SBARX, SBARY). If ***)
'(*** no status bar is desired, pass a 0 for the x and y. SBARLEN is ***)
'(*** the length you want the status bar to be. ***)
'(*** NOTICE: To unXOR the file, just pass the XORed file the the ***)
'(*** function with the _SAME_ encryption key. Given the nature of ***)
'(*** XOR, an individual decryption scheme is not needed. Note, too, ***)
'(*** that EKEY can only be from 0 to 255. ***)
'(*** --------------------------------------------------------------- ***)
FUNCTION File.XOR (FILE$, output$, ekey, sbarx, sbary, sbarlen)
'(*** Check if the input file passed exist. ***)
'(*** If the input file doesn't exist, exit with error ***)
'(*** value 0 [FALSE]. ***)
filenum = FREEFILE
OPEN FILE$ FOR BINARY AS filenum
IF LOF(filenum) = 0 THEN
'(*** Pass error value back since file didn't exist. ***)
File.XOR = 0
CLOSE filenum
'(*** Kill the 0 byte file we made by opening it. ***)
KILL FILE$
EXIT FUNCTION
END IF
'(*** Both files exist, open them. ***)
CLOSE filenum
OPEN FILE$ FOR INPUT AS filenum
outputnum = FREEFILE
OPEN output$ FOR OUTPUT AS outputnum
'(*** If we want a status bar, do the encryption with a status bar! ***)
IF sbarx > 0 THEN
'(*** Draw empty status bar and reset the byte count# to 0. ***)
LOCATE sbary, sbarx: PRINT STRING$(sbarlen, 177);
count# = 0
'(*** Encrypt/Decrypt the file. ***)
DO WHILE NOT EOF(1)
'(*** Read a byte from the file. ***)
bytes.left# = LOF(filenum) - LOF(outputnum)
IF bytes.left# < 100 THEN
read.bytes$ = INPUT$(bytes.left#, filenum)
chunk = bytes.left#
ELSE
read.bytes$ = INPUT$(100, filenum)
chunk = 100
END IF
'(*** Increment byte count#. ***)
count# = count# + chunk
'(*** XOR the bytes with encryption key. ***)
FOR byte.count = 1 TO chunk
changed.byte$ = changed.byte$ + CHR$(ASC(MID$(read.bytes$, byte.count, 1)) XOR ekey)
NEXT byte.count
'(*** Print it to the output file. ***)
PRINT #outputnum, changed.byte$;
changed.byte$ = ""
'(*** If a chunk of 100 bytes has been read, update status bar. ***)
IF count# MOD 1000 = 0 THEN
LOCATE sbary, sbarx
PRINT STRING$(sbarlen * (count# / LOF(1)), 219);
END IF
LOOP
LOCATE sbary, sbarx
PRINT STRING$(sbarlen, 219);
ELSE
'(*** We didn't want a status bar, so skip the status bar. This will ***)
'(*** give some extra speed because the print code is ignored. ***)
DO WHILE NOT EOF(1)
'(*** Read a byte from the file. ***)
bytes.left# = LOF(filenum) - LOF(outputnum)
IF bytes.left# < 100 THEN
read.bytes$ = INPUT$(bytes.left#, filenum)
chunk = bytes.left#
ELSE
read.bytes$ = INPUT$(100, filenum)
chunk = 100
END IF
'(*** XOR the bytes with encryption key. ***)
FOR byte.count = 1 TO chunk
changed.byte$ = changed.byte$ + CHR$(ASC(MID$(read.bytes$, byte.count, 1)) XOR ekey)
NEXT byte.count
'(*** Print it to the output file. ***)
PRINT #outputnum, changed.byte$;
changed.byte$ = ""
LOOP
END IF
'(*** Close the files we used. ***)
CLOSE filenum, outputnum
'(*** All done with no errors, so return a TRUE value. ***)
File.XOR = -1
END FUNCTION |
5. Da mit QB erstellte EXE Dateien DOS-EXEn sind, ist das nicht möglich. Das geht nur bei Windows-EXEn. Ist eben so. Du könntest höchstens eine Verknüpfung mit einem Symbol anlegen.
Viele Grüße!
Sebastian _________________
Die gefährlichsten Familienclans | Opas Leistung muss sich wieder lohnen - für 6 bis 10 Generationen! |
|
Nach oben |
|
 |
DarkLord
Anmeldungsdatum: 26.03.2005 Beiträge: 70 Wohnort: Rhade^^ oben bei muddi
|
Verfasst am: 26.03.2005, 20:09 Titel: |
|
|
Danke.. Qbasic.de kenn ich, da habe ich viele gute sachen gefunden... werde mal in der Wundertüte suchen^^  |
|
Nach oben |
|
 |
jb

Anmeldungsdatum: 14.01.2005 Beiträge: 2010
|
Verfasst am: 26.03.2005, 20:16 Titel: |
|
|
Zu 2:
Eine Alternative zum SLEEP-Befehl ist sicher
Code: |
DO: LOOP UNTIL INKEY$ <> ""
|
Dann einfach weiter im Programm. Den Tastaturpuffer leeren musst du dafür nicht...
jb |
|
Nach oben |
|
 |
Quark48

Anmeldungsdatum: 16.10.2004 Beiträge: 559 Wohnort: Saltendorf a.d. Naab bzw. Teublitz i.d. Oberpfalz / Bayern
|
Verfasst am: 29.03.2005, 19:14 Titel: |
|
|
Hallo!
Den Tastaturpuffer leert man übrigens mit
Code: |
FOR X = 1 to 15
Y$ = INKEY$
NEXT |
_________________ Grüßle, Stefan
***
Wenn ein Programm auf nem alten Rechner gut läuft, dann läuft´s auf nem neuen erst recht!
Ich habe/hatte keine feste Spange und auch keine Schwester. Der Rest stimmt. Es tut mir leid... :-/ |
|
Nach oben |
|
 |
jb

Anmeldungsdatum: 14.01.2005 Beiträge: 2010
|
Verfasst am: 29.03.2005, 20:26 Titel: |
|
|
Oder mit
Code: |
DEF SEG=0
POKE &H41A, PEEK (&H41C)
DEF SEG
|
was übrigens in der MonsterFAQ steht, und hier im Forum schonmal behandelt wurde.
jb |
|
Nach oben |
|
 |
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
|