A new expression requires (), [], or {} after type
-
Tuesday, April 07, 2009 1:36 AMHi All,
during compilation i encountered this errors.
this is the line causes errors.
String
aChar = new string Character((char)(int)XSTRING + i + 122).toString();
private string ENC_PASSW(string Passwrd, string INOUT)
{
string result = FuncStrSpace(Passwrd,10) ;
string YSTRING, XSTRING ;
if (INOUT == "IN")
{
YSTRING =
"";
for (int i = 0; i <Passwrd.Length; i++)
{
XSTRING = Passwrd.Substring(i,1) ;
//int asc = (int)XSTRING;
//XSTRING = asc + i + 122;
String aChar = new string Character((char)(int)XSTRING + i + 122).toString();
YSTRING = YSTRING + aChar;
}
}
return YSTRING ;
}
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS
All Replies
-
Tuesday, April 07, 2009 2:32 AM
Unfortunatelly, you haven't asked any questions... so I'll assume that your concern is why that line gives you an error.
There are 4 ways of using the new keyword (that I can think of).
- Creating a new instance: new Form()
- Creating a new array: new int[] { 1, 2 } / new int[10]
- Creating a new anonymous type: new { Name = "John" }
- Shadowing a base method: public new string ToString()
As you can see, none of them comply with what you are doing.
What is Character?
If Character is a method that returns a string, then you should use:
String aChar = Character((char)(int)XSTRING + i + 122).toString();
But since that is what you've already done with XSTRING, I'd guess it's not.
So, please, elaborate a little further so someone can help you.
By the way, I'll repost your code formatted so that it is readable:
private string ENC_PASSW(string Passwrd, string INOUT) { string result = FuncStrSpace(Passwrd,10) ; string YSTRING, XSTRING ; if (INOUT == "IN") { YSTRING = ""; for (int i = 0; i <Passwrd.Length; i++) { XSTRING = Passwrd.Substring(i,1) ; //int asc = (int)XSTRING; //XSTRING = asc + i + 122; String aChar = new string Character((char)(int)XSTRING + i + 122).toString(); YSTRING = YSTRING + aChar; } } return YSTRING ; }
Regards,
Fernando.
/* No comments */ -
Tuesday, April 07, 2009 2:36 AMHi Fernando,
I try to ascii my string then chr it.
this is the function to decrypt and encrypt in foxpro.
in foxpro i can do somehthing like this.
YSTRING=YSTRING+CHR(ASC(XSTRING) + I + 122)
in c# i try to convert it.
the outcome must be matched so i can compare it with foxpro table.
Thanks.
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS -
Tuesday, April 07, 2009 2:43 AMIn foxpro you'll have you chr and asc functions, which you don't in C#.
But don't worry, you'll get the same results by either casting to byte a char, or casting a char to byte.
(char)97 == 'a'
(byte)'a' == 97
You get the idea.
Now to get a char out of a string, instead of substringing with length 1, simply use the indexer.
string str = "Hello";
str[1] == 'e'.
Hope this guides you in the right path.
/* No comments */ -
Tuesday, April 07, 2009 2:53 AMHi fernando,
Thanks for your advice. Will revert to all of u it work out or not.
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS -
Tuesday, April 07, 2009 3:05 AMHi fernando,
Byte
bbyte = result.Substring(i, 1).+i+122 ;
i = is a looping use for each string.
let said user input "ABC" as password i will add 7 spaces to "ABC " to be new string pass to my functions.
then from there result = "ABC ".
so how i can ascii it to A = 188 ?
thanks.
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS -
Tuesday, April 07, 2009 3:20 AM
for (int i = 0; i < result.Length; i++) { byte code = (byte)result[i] + 122 + i; // do something with b }
That should do the trick.
In fact, the entire code, I think, would be something like this:
char[] encodedChars = new char[result.Length]; for (int i = 0; i < result.Length; i++) { byte code = (byte)result[i] + 122 + i; encodedChars[i] = (char)code; } string encodedString = new string (encodedChars);
I can't test it right now, so it's up to you to fix any issues. :D
Regards.
/* No comments */ -
Tuesday, April 07, 2009 3:26 AMHi Fernando,
This line had error.
byte
code = (byte)result[i] + 122 + i;
Error 3 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
may i know how i can solve it ?
Thanks.
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS -
Tuesday, April 07, 2009 3:34 AM
Try:
byte code = (byte)((byte)result[i] + 122 + i);
Also, since C# arrays (including the string) start at 0, it should be ... + 123 + i.
/* No comments */- Marked As Answer by yanyee Tuesday, April 07, 2009 3:37 AM
-
Tuesday, April 07, 2009 3:40 AMHi fernando,
ok ok tks.
iT solved butencodedChars = (
char)code; causes error too.
Error 3 Cannot implicitly convert type 'char' to 'char[]' .
Thanks.
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS -
Tuesday, April 07, 2009 3:46 AM
I edited the code.
It's encodedChars[i]
Also, remember to change to 123 instead of 122.
I'm guessing you are enconding passwords the same way you did in foxpro. I recommend to use a whole different approach towards enconding passwords now that you have the entire .NET framework, specially the System.Security.Cryptography namespace. Search this forum, there are a lot of threads regarding passwords and encryption.
/* No comments */- Marked As Answer by yanyee Tuesday, April 07, 2009 3:56 AM
-
Tuesday, April 07, 2009 3:55 AMHi fernando,
Yes i had changed it to 123 but the problem is i using oledb conencted to foxpro table and i need match the password entered by user match with foxpro table.
so i need using same functions developed in foxpro to c#.
thanks.
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS -
Tuesday, April 07, 2009 3:59 AMHi fernando,
Its so weird byte 124 = 190 and not 209.
in foxpro ASC(124) = 209 .
so at the end result it not match.
only the first 123 + i(0) = 208 its match.
Thanks.
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS -
Tuesday, April 07, 2009 5:48 AMHi Fernando,
so sorry its my mistake. Its correct.
Thanks.
MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS

