How do I insert a char in an unsigned long* v?

This is a discussion on How do I insert a char in an unsigned long* v? within the C++ Programming forums, part of the General Programming Boards category; Hello folks! How do I insert in an unsigned long * v; //supossed 4 bytes long, isn't it? one to ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    30

    How do I insert a char in an unsigned long* v?

    Hello folks!

    How do I insert in an

    unsigned long * v; //supossed 4 bytes long, isn't it?

    one to 4 chars?
    But if it is

    unsigned long *const v;



    Thanks
    Robert

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    huh?

    what is *v?

  3. #3
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    Code:
    long val;
    char str[4];
    memcpy(&val,str,4);
    Code:
    long val=0;
    char str[4];
    
    for(int i=0; i<4; i++) {
       val |= ((long)str[i]) << (i*8);
    }

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    30

    Smile

    unsigned long * v;
    v is the name of the pointer, assumed to be an int.
    You can use *ptr, *pointer, *your_preffered_name, etc.
    I quoted from my listing.

    Robert

  5. #5
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    ufhm I did the opposite!

    Code:
    long val = 0xc0de;
    char str[4]; //there is no '\0' char... place it yourself if you want
    
    memcpy(str,&val,sizeof(val));

    Code:
    long val = 0xc0de;
    char str[4];
    
    for(int i=0; i<4;i++)
        str[i] = (char)(val >> (i*8));

    by the way ...
    why would you want this?
    is for the :
    Code:
    void code(long* v, long* k)  {              
    	unsigned long y=v[0],z=v[1], sum=0,n=32 ;
    
    	while (n-->0) {
    		sum += DELTA ;
    		y += (z<<4)+k[0] ^ z+sum ^ (z>>5)+k[1] ;
    		z += (y<<4)+k[2] ^ y+sum ^ (y>>5)+k[3] ; 
    	} 
    	v[0]=y;
    	v[1]=z;
    }

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    30
    [QUOTE]Originally posted by borko_b
    [B]
    Code:
    long val;
    char str[4];
    memcpy(&val,str,4);
    Yes, thank you. This will do.
    I am really crushed that I didn't see it. I need a vacation.

    Robert

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    30

    Angry A cup of tea, maybe

    ufhm I did the opposite!
    It's OK, I saw the idea.



    by the way ...
    why would you want this?
    is for the :
    Code:
    void code(long* v, long* k)  {              
    ...

    Is that so obvious?

    Do I have to hide myself... to enjoy my cup of tea... :-(


    Robert

  8. #8
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100

    No !
    don't hide it!

    I am a fan of TEA algorithm
    currently i am making an OpenSource TEA file encoding tool
    wich will be both Win32 and Linux compatible code

    So i saw the long *v and made the connection!

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    30

    Angry Shhhhh!

    Will you keep it low!?

    [paranoid]Where do I hide... where do I go...[/paranoid]


    Robert

  10. #10
    Registered User
    Join Date
    Mar 2002
    Posts
    30
    [QUOTE]Originally posted by borko_b
    [B]
    No !
    don't hide it!

    ... currently i am making an OpenSource TEA file ...
    wich will be both Win32 and Linux compatible code

    OK, ok. Keep me informed, please.

    [paranoid]BTW, did you notice the anvelope that marks this tread? It has been sealed from the very beginning. What would this mean?[/paranoid]

    [more paranoid]I didn't see another like this! Wouldn't you think of...[/more paranoid]

    [paranoid]Where do I go... where do I hide...[/paranoid]

  11. #11
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    >>BTW, did you notice the anvelope that marks this tread? It has
    >>been sealed from the very beginning. What would this mean?

    i've got no idea...

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    oh is it a pointer aaah ok..
    i know its a pointer i just didn't get your question.

  13. #13
    Registered User
    Join Date
    Mar 2002
    Posts
    30

    Unhappy

    Originally posted by pode
    oh is it a pointer aaah ok..
    i know its a pointer i just didn't get your question.
    ?!? which part ?!? I got really confused about this!

    this is for borko_b

    You really did squeeze those chars in the unsig. long?
    And did it work? :-)

    Robert

  14. #14
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    >>You really did squeeze those chars in the unsig. long?
    >>And did it work? :-)

    No actually ... I don't use char s for the key..

    i generate numbers like rand() from a string
    and i pass them to the code() and decode()
    and then modify them by a formula
    after each code/decode so that the key is different
    next time

  15. #15
    Registered User
    Join Date
    Mar 2002
    Posts
    30
    No actually ... I don't use char s for the key..

    i generate numbers like rand() from a string
    what string? some user input?
    and i pass them to ...
    and then modify them by a formula
    after each code/decode so that the key is different
    next time
    Are you able to save today and to read tomorrow this way?
    being a simmetrical alg., aren't you exposing the user instead of protecting him?


    Robert

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C problem with legacy code
    By andy_baptiste in forum C Programming
    Replies: 4
    Last Post: 05-19-2008, 07:14 AM
  2. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 06:59 AM
  3. Swap a bit
    By mr_nice! in forum C Programming
    Replies: 7
    Last Post: 03-01-2004, 03:15 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 12:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21