473,378 Members | 1,407 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,378 software developers and data experts.

Convert from Delphi to C#

Hello,
I'm trying to convert these to functions to c#

const
C1 = 52845;
C2 = 22719;

function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
setlength(result,length(s));
for I := 1 to Length(S) do begin
Result[i] := char(byte(S[i]) xor (Key shr 8));
Key := (byte(Result[i]) + Key) * C1 + C2;
end;
end;

function Decrypt(const S: String; Key: Word): String;
var
I: byte;
begin
setlength(result,length(s));
for I := 1 to Length(S) do begin
Result[i] := char(byte(S[i]) xor (Key shr 8));
Key := (byte(S[i]) + Key) * C1 + C2;
end;
end;

Thanks
Mel
Nov 17 '05 #1
2 3468
really lousy encryption.

You may want to consider using the encryption routines in .Net. The one you
show is really bad. Not much better than a secret decoder ring
(http://en.wikipedia.org/wiki/Secret_decoder_ring) on a very slightly better
scale. Still, I wouldn't trust actual sensitive data to it.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
news:u%***************@TK2MSFTNGP11.phx.gbl...
Hello,
I'm trying to convert these to functions to c#

const
C1 = 52845;
C2 = 22719;

function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
setlength(result,length(s));
for I := 1 to Length(S) do begin
Result[i] := char(byte(S[i]) xor (Key shr 8));
Key := (byte(Result[i]) + Key) * C1 + C2;
end;
end;

function Decrypt(const S: String; Key: Word): String;
var
I: byte;
begin
setlength(result,length(s));
for I := 1 to Length(S) do begin
Result[i] := char(byte(S[i]) xor (Key shr 8));
Key := (byte(S[i]) + Key) * C1 + C2;
end;
end;

Thanks
Mel

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
0
by: W. D. | last post by:
Hi Folks, My Delphi is rusty, and my C is corroded. Am I understanding this properly? CPP Code: TMainForm *MainForm Is this a declaration for a form named 'MainForm'
2
by: Peter Williams | last post by:
Hi All, I need to port the following (small) C language function to Delphi: double Rand(void) { return rand()/(1.0 + (double)RAND_MAX); } NB -- elsewhere in the program randomize is called...
2
by: Mel WEaver | last post by:
Hello, I have the following delphi structure for a binary file. I'm looking for idea how to read this file. Mel type TMenuDataStruct = packed record exename : string;
8
by: mesutalturk | last post by:
How do i convert the following C# code to Delphi? public static uint GenerateSiteID(string SiteName) { uint id = 0; char arr = SiteName.ToCharArray(); //Convert the sitename to a Char Array...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.