943,840 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 7372
  • Java RSS
Aug 4th, 2004
0

string translation

Expand Post »
Hey there,

First off I'm really new to Java so please bear with me. I need to translate a line of text from one form to another. An example line segment has the following format:

" step(sent(1,A,B,vars(Na,Rv,ped(pk(B),cat(N
a,A)))))"

This means that at step 1, A sends to B that which is contained in vars() i.e. Na, Rv and encryption of Na and A (concatenated) using B's public key [ped(pk(B),cat(Na,A))]

The output format I need is the following:

"Knows_B,time_1(Received(B,time_1,(Na,Rv,enc({Na,A},pk_B))))" (ii)

Basically this is the same information that is in the input format but I just need to translate it to the output format above. From what I've read I think i need to use string tokenisers to separate out the input format and thus build up the output form. However I really am at a loss as to how to begin coding this translation. If anyone has the time could they perhaps give me an example of some code that might solve this problem.
If anyone needs more information regarding the input format and how it's related to the output format I will try and elaborate some more on their connection.

Thanks a million.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
macca1979 is offline Offline
6 posts
since Jul 2004
Aug 4th, 2004
0

Re: string translation

A string tokenizer will separate that long string in an array of small strings.
I.e.
If you had the string "My@Name@Is@bobby@!" (that's not my name btw ) and you set up a string tokenizer to deliminate by @ you'd end up with an array of 5 elements.
"My","Name","is","bobby","!"
Then you could loop through the array trying to match certain cases.
Java Syntax (Toggle Plain Text)
  1. import java.util.*;
  2. public class TokenizerTest{
  3. public static void main(String[] args){
  4. String input = "step(sent(1,A,B,vars(Na,Rv,ped(pk(B),cat(Na,A)))))"
  5. String output = null;
  6. StringTokenizer st = new StringTokenizer(input,")");
  7. while(st.hasMoreTokens()){
  8. if(st.nextToken().equals("some string")){
  9. // do stuff here
  10. }
  11. }
  12. System.out.println("Output: "+ output);
  13. }
  14. }
I'm not sure how the input relates to the output so you can figure that out. But atleast you should know how now. After you tokenize by ")" you'll be left with 8 tokens:
"step"
"sent"
"1,A,B,vars"
"Na,Rv,ped"
"Pk"
"B"
",cat"
"Na,A"

If you want you could deliminate even further by "," but that's up to you.
Reputation Points: 46
Solved Threads: 2
Junior Poster
Iron_Cross is offline Offline
117 posts
since Jul 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: java basic
Next Thread in Java Forum Timeline: "String class"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC