Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Encryption program works differently in Virtual Pascal for Win32? Posted by PP2005 on 3 Aug 2006 at 8:12 AM
Hi!

I have a question about this source code:

http://www.programmersheaven.com/download/4123/download.aspx

I've downloaded it for use in a game I've made. It's purpose is to encrypt the hi-score file. It works perfectly in the DOS version of the game, but I'm now porting the game to Win32 and I've run into a problem.
The encryption works as it should within the Win32 version of the game, but when I try to use a hi-score file made with the DOS version in the Win32 version, the decryption comes out completely messed up -- despite the fact that I've used the exact same code key in both versions! Why is that?!
Report
Re: Encryption program works differently in Virtual Pascal for Win32? Posted by zibadian on 3 Aug 2006 at 8:54 AM
: Hi!
:
: I have a question about this source code:
:
: http://www.programmersheaven.com/download/4123/download.aspx
:
: I've downloaded it for use in a game I've made. It's purpose is to encrypt the hi-score file. It works perfectly in the DOS version of the game, but I'm now porting the game to Win32 and I've run into a problem.
: The encryption works as it should within the Win32 version of the game, but when I try to use a hi-score file made with the DOS version in the Win32 version, the decryption comes out completely messed up -- despite the fact that I've used the exact same code key in both versions! Why is that?!
:
It could be that the endianness is different between the two. See http://en.wikipedia.org/wiki/Big_endian for info about endianness.
Most often encryptions are based on bit scrambling. If the endianness is different, then the unscrambling goes wrong.
Report
Re: Encryption program works differently in Virtual Pascal for Win32? Posted by PP2005 on 3 Aug 2006 at 12:24 PM
: : Hi!
: :
: : I have a question about this source code:
: :
: : http://www.programmersheaven.com/download/4123/download.aspx
: :
: : I've downloaded it for use in a game I've made. It's purpose is to encrypt the hi-score file. It works perfectly in the DOS version of the game, but I'm now porting the game to Win32 and I've run into a problem.
: : The encryption works as it should within the Win32 version of the game, but when I try to use a hi-score file made with the DOS version in the Win32 version, the decryption comes out completely messed up -- despite the fact that I've used the exact same code key in both versions! Why is that?!
: :
: It could be that the endianness is different between the two. See http://en.wikipedia.org/wiki/Big_endian for info about endianness.
: Most often encryptions are based on bit scrambling. If the endianness is different, then the unscrambling goes wrong.
:


Thanks for your reply! I've now read the wikipedia info on endianess and while I understand the concept I'll be damned if I know how to apply this to my program -- or if I can at all! I guess it isn't a problem with the source code as it doesn't change, but must be how the code is compiled in Borland Pascal versus Virtual Pascal?
Report
Re: Encryption program works differently in Virtual Pascal for Win32? Posted by zibadian on 3 Aug 2006 at 1:09 PM
: : : Hi!
: : :
: : : I have a question about this source code:
: : :
: : : http://www.programmersheaven.com/download/4123/download.aspx
: : :
: : : I've downloaded it for use in a game I've made. It's purpose is to encrypt the hi-score file. It works perfectly in the DOS version of the game, but I'm now porting the game to Win32 and I've run into a problem.
: : : The encryption works as it should within the Win32 version of the game, but when I try to use a hi-score file made with the DOS version in the Win32 version, the decryption comes out completely messed up -- despite the fact that I've used the exact same code key in both versions! Why is that?!
: : :
: : It could be that the endianness is different between the two. See http://en.wikipedia.org/wiki/Big_endian for info about endianness.
: : Most often encryptions are based on bit scrambling. If the endianness is different, then the unscrambling goes wrong.
: :
:
:
: Thanks for your reply! I've now read the wikipedia info on endianess and while I understand the concept I'll be damned if I know how to apply this to my program -- or if I can at all! I guess it isn't a problem with the source code as it doesn't change, but must be how the code is compiled in Borland Pascal versus Virtual Pascal?
:
You can remedy this by forcing both compilers to use a single storage method using a compiler directive, or by rewriting the file IO to make sure the order of the bytes is identical.
Report
Re: Encryption program works differently in Virtual Pascal for Win32? Posted by Alcatiz on 3 Aug 2006 at 1:44 PM
: : : : Hi!
: : : :
: : : : I have a question about this source code:
: : : :
: : : : http://www.programmersheaven.com/download/4123/download.aspx
: : : :
: : : : I've downloaded it for use in a game I've made. It's purpose is to encrypt the hi-score file. It works perfectly in the DOS version of the game, but I'm now porting the game to Win32 and I've run into a problem.
: : : : The encryption works as it should within the Win32 version of the game, but when I try to use a hi-score file made with the DOS version in the Win32 version, the decryption comes out completely messed up -- despite the fact that I've used the exact same code key in both versions! Why is that?!
: : : :
: : : It could be that the endianness is different between the two. See http://en.wikipedia.org/wiki/Big_endian for info about endianness.
: : : Most often encryptions are based on bit scrambling. If the endianness is different, then the unscrambling goes wrong.
: : :
: :
: :
: : Thanks for your reply! I've now read the wikipedia info on endianess and while I understand the concept I'll be damned if I know how to apply this to my program -- or if I can at all! I guess it isn't a problem with the source code as it doesn't change, but must be how the code is compiled in Borland Pascal versus Virtual Pascal?
: :
: You can remedy this by forcing both compilers to use a single storage method using a compiler directive, or by rewriting the file IO to make sure the order of the bytes is identical.
:
Hi !
Doesn't the problem reside in the length of the Word type ?
It's 16-bit long in Borland Pascal 32-bit in Virtual Pascal.
You can either use the SmallWord type instead of Word or use the {&Use32-} directive.
Report
Re: Encryption program works differently in Virtual Pascal for Win32? Posted by zibadian on 3 Aug 2006 at 5:30 PM
: : : : : Hi!
: : : : :
: : : : : I have a question about this source code:
: : : : :
: : : : : http://www.programmersheaven.com/download/4123/download.aspx
: : : : :
: : : : : I've downloaded it for use in a game I've made. It's purpose is to encrypt the hi-score file. It works perfectly in the DOS version of the game, but I'm now porting the game to Win32 and I've run into a problem.
: : : : : The encryption works as it should within the Win32 version of the game, but when I try to use a hi-score file made with the DOS version in the Win32 version, the decryption comes out completely messed up -- despite the fact that I've used the exact same code key in both versions! Why is that?!
: : : : :
: : : : It could be that the endianness is different between the two. See http://en.wikipedia.org/wiki/Big_endian for info about endianness.
: : : : Most often encryptions are based on bit scrambling. If the endianness is different, then the unscrambling goes wrong.
: : : :
: : :
: : :
: : : Thanks for your reply! I've now read the wikipedia info on endianess and while I understand the concept I'll be damned if I know how to apply this to my program -- or if I can at all! I guess it isn't a problem with the source code as it doesn't change, but must be how the code is compiled in Borland Pascal versus Virtual Pascal?
: : :
: : You can remedy this by forcing both compilers to use a single storage method using a compiler directive, or by rewriting the file IO to make sure the order of the bytes is identical.
: :
: Hi !
: Doesn't the problem reside in the length of the Word type ?
: It's 16-bit long in Borland Pascal 32-bit in Virtual Pascal.
: You can either use the SmallWord type instead of Word or use the {&Use32-} directive.
:
I never considered that, because as a TP7, 16-bit Delphi, and 32-bit Delphi programmer I've never seen a word being anything else than a 16-bit unsigned integer. But that's a good point, and worth looking into for PP2005.
Report
Re: Encryption program works differently in Virtual Pascal for Win32? Posted by PP2005 on 4 Aug 2006 at 12:24 AM
: : : : : : Hi!
: : : : : :
: : : : : : I have a question about this source code:
: : : : : :
: : : : : : http://www.programmersheaven.com/download/4123/download.aspx
: : : : : :
: : : : : : I've downloaded it for use in a game I've made. It's purpose is to encrypt the hi-score file. It works perfectly in the DOS version of the game, but I'm now porting the game to Win32 and I've run into a problem.
: : : : : : The encryption works as it should within the Win32 version of the game, but when I try to use a hi-score file made with the DOS version in the Win32 version, the decryption comes out completely messed up -- despite the fact that I've used the exact same code key in both versions! Why is that?!
: : : : : :
: : : : : It could be that the endianness is different between the two. See http://en.wikipedia.org/wiki/Big_endian for info about endianness.
: : : : : Most often encryptions are based on bit scrambling. If the endianness is different, then the unscrambling goes wrong.
: : : : :
: : : :
: : : :
: : : : Thanks for your reply! I've now read the wikipedia info on endianess and while I understand the concept I'll be damned if I know how to apply this to my program -- or if I can at all! I guess it isn't a problem with the source code as it doesn't change, but must be how the code is compiled in Borland Pascal versus Virtual Pascal?
: : : :
: : : You can remedy this by forcing both compilers to use a single storage method using a compiler directive, or by rewriting the file IO to make sure the order of the bytes is identical.
: : :
: : Hi !
: : Doesn't the problem reside in the length of the Word type ?
: : It's 16-bit long in Borland Pascal 32-bit in Virtual Pascal.
: : You can either use the SmallWord type instead of Word or use the {&Use32-} directive.
: :
: I never considered that, because as a TP7, 16-bit Delphi, and 32-bit Delphi programmer I've never seen a word being anything else than a 16-bit unsigned integer. But that's a good point, and worth looking into for PP2005.
:


Thanks for the input, Alcatiz! I tried changing all the word types in my encryption unit to smallword, but that didn't change anything. Neither does using the {&Use32-} compiler directive, so I guess the problem isn't in the word type.

Zibadian: I've looked for compiler directives for setting a single storage method, but haven't found any. Do you have any idea what it's called? I'm afraid that rewriting the file IO is a bit beyond my programming capabilities... :o(
Report
Re: Encryption program works differently in Virtual Pascal for Win32? Posted by zibadian on 4 Aug 2006 at 4:39 AM
: : : : : : : Hi!
: : : : : : :
: : : : : : : I have a question about this source code:
: : : : : : :
: : : : : : : http://www.programmersheaven.com/download/4123/download.aspx
: : : : : : :
: : : : : : : I've downloaded it for use in a game I've made. It's purpose is to encrypt the hi-score file. It works perfectly in the DOS version of the game, but I'm now porting the game to Win32 and I've run into a problem.
: : : : : : : The encryption works as it should within the Win32 version of the game, but when I try to use a hi-score file made with the DOS version in the Win32 version, the decryption comes out completely messed up -- despite the fact that I've used the exact same code key in both versions! Why is that?!
: : : : : : :
: : : : : : It could be that the endianness is different between the two. See http://en.wikipedia.org/wiki/Big_endian for info about endianness.
: : : : : : Most often encryptions are based on bit scrambling. If the endianness is different, then the unscrambling goes wrong.
: : : : : :
: : : : :
: : : : :
: : : : : Thanks for your reply! I've now read the wikipedia info on endianess and while I understand the concept I'll be damned if I know how to apply this to my program -- or if I can at all! I guess it isn't a problem with the source code as it doesn't change, but must be how the code is compiled in Borland Pascal versus Virtual Pascal?
: : : : :
: : : : You can remedy this by forcing both compilers to use a single storage method using a compiler directive, or by rewriting the file IO to make sure the order of the bytes is identical.
: : : :
: : : Hi !
: : : Doesn't the problem reside in the length of the Word type ?
: : : It's 16-bit long in Borland Pascal 32-bit in Virtual Pascal.
: : : You can either use the SmallWord type instead of Word or use the {&Use32-} directive.
: : :
: : I never considered that, because as a TP7, 16-bit Delphi, and 32-bit Delphi programmer I've never seen a word being anything else than a 16-bit unsigned integer. But that's a good point, and worth looking into for PP2005.
: :
:
:
: Thanks for the input, Alcatiz! I tried changing all the word types in my encryption unit to smallword, but that didn't change anything. Neither does using the {&Use32-} compiler directive, so I guess the problem isn't in the word type.
:
: Zibadian: I've looked for compiler directives for setting a single storage method, but haven't found any. Do you have any idea what it's called? I'm afraid that rewriting the file IO is a bit beyond my programming capabilities... :o(
:
In Delphi I cannot fins it either, but I found the Swap() function.
This kind of reading/writing is actually quite simple. The code below shows one way of copying the value of a word into an array:
type
  TMyWord = array[0..1] of byte;
var
  SomeWord: word;
  SomeMyWord: TMyWord;
begin
  Move(SomeWord, SomeMyWord, SizeOf(SomeWord));
end;

Then you can directly control the order of the bytes inthe writing part:
  // Same endianness
  write(f, SomeMyWord[0], SomeMyWord[1]);
  // Different endianness
  write(f, SomeMyWord[1], SomeMyWord[0]);

Reading it is quite similar:
  // Same endianness
  read(f, SomeMyWord[0], SomeMyWord[1]);
  // Different endianness
  read(f, SomeMyWord[1], SomeMyWord[0]);
  Move(SomeMyWord, SomeWord, SizeOf(SomeWord));

You can expand these to include all multi-byte types as you see fit.
Report
Re: Encryption program works differently in Virtual Pascal for Win32? Posted by PP2005 on 5 Aug 2006 at 1:51 AM
: In Delphi I cannot fins it either, but I found the Swap() function.
: This kind of reading/writing is actually quite simple. The code below shows one way of copying the value of a word into an array:
:
: type
:   TMyWord = array[0..1] of byte;
: var
:   SomeWord: word;
:   SomeMyWord: TMyWord;
: begin
:   Move(SomeWord, SomeMyWord, SizeOf(SomeWord));
: end;
: 

: Then you can directly control the order of the bytes inthe writing part:
:
:   // Same endianness
:   write(f, SomeMyWord[0], SomeMyWord[1]);
:   // Different endianness
:   write(f, SomeMyWord[1], SomeMyWord[0]);
: 

: Reading it is quite similar:
:
:   // Same endianness
:   read(f, SomeMyWord[0], SomeMyWord[1]);
:   // Different endianness
:   read(f, SomeMyWord[1], SomeMyWord[0]);
:   Move(SomeMyWord, SomeWord, SizeOf(SomeWord));
: 

: You can expand these to include all multi-byte types as you see fit.
:


I'll try this. Thanks for you help!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.