PDA

View Full Version : change the ascii code, problem.




MNiazmand
Jun 4, 2011, 02:34 PM
i've found myself in trouble. could you please do me a favor? how can i make myself assure about my program, that if the user presses the 'a' key, it's ascii code change to the one that programer wants and then show it in the NSTextField. thanks for your attention.

example:

http://i55.tinypic.com/2r7op3p.png



jared_kipe
Jun 4, 2011, 03:24 PM
Man, there seems to be a sudden influx of "simple" encryption threads all of a sudden.

This appears to be a character substitution cypher.

the "ll" -> "ee" suggests a one to one mapping.

However the difference between l and e, and e and b are not the same, so it suggests something more sophisticated than a simple C = P + a mod 26

MNiazmand
Jun 4, 2011, 03:55 PM
Oops!

My problem is :

1 - how to mapping keyboard
2 - change ascii code when key-pressed { on key pressed in NSTextField }
3 - real-time changing. {run time}

jared_kipe
Jun 4, 2011, 04:01 PM
Making the assumptions that 'hello' becomes 'HELLO' for the purposes on the cypher, I did some quick math using the 'E'->'B' and 'L'->'E' assuming
C = aP + b mod 26

I ended up with
C = 19 * P + 3 mod 26


Which will make 'E'->'B' and 'L'->'E', but not 'H'->'A' and 'O'->'Y'

So I would need more information about the way this is programmed, or at least a good deal more data, say capital letters in the input.

But to be fair I didn't even really understand your question, I just assumed you wanted to reverse engineer this cypher/program.

jared_kipe
Jun 4, 2011, 04:07 PM
Oops!

My problem is :

1 - how to mapping keyboard
2 - change ascii code when key-pressed { on key pressed in NSTextField }
3 - real-time changing. {run time}

Then I assume you have some kind of 1:1 mapping already written, say in a lookup table.

NSTextField has a delegate method that looks promising -controlTextDidChange

Implement that to either:
1) Copy the contents of the textfield into a NSMutableString, and then walk through each character and lookup then replace the character. Display this string in the other textField.

2) Get the last character of the current string in the textField, and do the lookup and then append it to the string in the other textField.

Either option would be pretty trivial, but option 2 is more efficient.

MNiazmand
Jun 4, 2011, 04:40 PM
Then I assume you have some kind of 1:1 mapping already written, say in a lookup table.

NSTextField has a delegate method that looks promising -controlTextDidChange

Implement that to either:
1) Copy the contents of the textfield into a NSMutableString, and then walk through each character and lookup then replace the character. Display this string in the other textField.

2) Get the last character of the current string in the textField, and do the lookup and then append it to the string in the other textField.

Either option would be pretty trivial, but option 2 is more efficient.


thx mr jared_kipe

but : i want work with ascii code . because my language not english and
I'm switching keys pressed characters in the English language with my language ASCII .

How did this act ?
I'm grateful for the example bring.

thx for help.

btw my language is persian .;)

gnasher729
Jun 4, 2011, 05:14 PM
thx mr jared_kipe

but : i want work with ascii code . because my language not english and
I'm switching keys pressed characters in the English language with my language ASCII .

How did this act ?
I'm grateful for the example bring.

thx for help.

btw my language is persian .;)

ASCII is an ancient and very limited code with only 128 characters. It is not even enough to write proper English, for example words like nave, names like Zo, proper “quote” characters, they all cannot be written in ASCII. And forget about writing Persian with ASCII characters (that's Arabic with a few extensions, if I remember right).

Go to System Preferences, "Language and Text", "Input Sources". At the top of the list, turn on "Keyboard and Character Viewer". That gets you the "Character Viewer" in the menubar. Check it out to get some idea about the range of different characters that are available. You should also enable a Persian keyboard, so you can type text like ضصثقف غعهخح شسیبل اتنم ظطذدز رو.

Then go to www.unicode.org to learn about Unicode, which is what any reasonable person (and all of the Cocoa code) uses to represent text, written in _any_ language. Any text field in Cocoa handles entering Persian text automatically.

MNiazmand
Jun 4, 2011, 05:28 PM
thx for help .

but i don't add a new keyboard .

i want writing with especial font of my language.
my font is not standard keyboard layout ,
So
I have to switch characters entered
Fits with the Persian characters .

Now what should be ???????:(:(:(

jared_kipe
Jun 4, 2011, 05:40 PM
All of the above is true. HOWEVER NSStrings are UTF, thus you can and should be able to pull the above description off going from ASCII characters into persian.

NSString's -characterAtIndex: returns a unichar which is an unsigned short. So will probably not return what you expect for multi byte characters like π and , but there is NO reason you can't implement lookups/replaces from US-keyboard entries like 'a' -> '' (whatever persian character you want)

Just use NSMutableString's -appendString: @"" or -replaceCharactersInRange: lastCharacterRange withString: @""
, for 1) and 2) respectively.

jared_kipe
Jun 4, 2011, 05:52 PM
thx for help .

but i don't add a new keyboard .

i want writing with especial font of my language.
my font is not standard keyboard layout ,
So
I have to switch characters entered
Fits with the Persian characters .

Now what should be ???????:(:(:(

Ok...

Both the proposed ideas (previously referred to as 1) and 2)) will do exactly what you are looking to do.

Is your screenshot a mockup or something then?

....
IBOutlet NSTextField *inputField;
IBOutlet NSTextField *outputField;
....

- (void)controlTextDidChange: (NSNotification *)aNotification {
//psudo code
stringIn = inputField string
stringOut = new NSMutableString
for each character in string {
substitute = replacement for character
stringOut append substitute
}

outputField set to stringOut
}


EDIT: Also, this implementation of 1) would work pretty well for a file or some other string/data input too. You just need to make a function/method to do the replacement for character lookup.

gnasher729
Jun 4, 2011, 05:54 PM
thx for help .

but i don't add a new keyboard .

i want writing with especial font of my language.
my font is not standard keyboard layout ,
So
I have to switch characters entered
Fits with the Persian characters .

Now what should be ???????:(:(:(

Well, I managed to enter arabic characters into Safari without problems, and I can enter arabic characters into any text field in any Cocoa application without problems, just by switching the keyboard, no programming needed. All the characters are available in the Arial, Courier, Times New Roman, Microsoft Sans Serif, Tahoma, DejaVu, or in specialzed fonts like Al Bayan, Baghdad, Geeza Pro, KufiStandard, Nadeem.

If you insist on doing this by hand, use the manuals from www.unicode.org or the "Character Viewer" that you can turn on in the menubar to find out which codes to use. And it is Unicode, not ASCII.

jared_kipe
Jun 4, 2011, 05:59 PM
Well, I managed to enter arabic characters into Safari without problems, and I can enter arabic characters into any text field in any Cocoa application without problems, just by switching the keyboard, no programming needed. All the characters are available in the Arial, Courier, Times New Roman, Microsoft Sans Serif, Tahoma, DejaVu, or in specialzed fonts like Al Bayan, Baghdad, Geeza Pro, KufiStandard, Nadeem.

If you insist on doing this by hand, use the manuals from www.unicode.org or the "Character Viewer" that you can turn on in the menubar to find out which codes to use. And it is Unicode, not ASCII.

I read it as he has a font that makes "a" look like some persian character, so he just replace "a" with "b" because the fonts glyph of "b" is what he wants to show up when he types "a"

MNiazmand
Jun 5, 2011, 09:34 AM
Jared's
Thanks for your help.
could i have your mailing address, please ?
it would be very nice to talk with you more about my problem.

Do not you think that the control key and press
ASCII code switching is the best solution.?

by the way its my mailing address :
niazmand@msn.com || my.niazmand@aol.com

jared_kipe
Jun 5, 2011, 11:50 AM
Jared's
Thanks for your help.
could i have your mailing address, please ?
it would be very nice to talk with you more about my problem.


I'll email you later today probably.


Do not you think that the control key and press
ASCII code switching is the best solution.?

Well since you never mentioned the control key before I am once again in the dark as to what you are trying to accomplish.

Out of curiosity do you happen to speak french better than english?

I think maybe you've made some assumptions as to how the problem should be solved. Maybe write a detailed explanation of what the problem is, and let us think about some solutions.

MNiazmand
Jun 5, 2011, 02:11 PM
I'll email you later today probably.


i'm waiting for you .