anchor.diff:      {false,[]};
   check_session_cookie([],_,_,_) ->
       {false,[]};
  -check_session_cookie(Cookie,ExpirationTime,FSessionKey,ServerKey) when is_binary(Cookie)->
  +check_session_cookie(ECookie,ExpirationTime,FSessionKey,ServerKey) ->
  +    Cookie=hexstr_to_bin(ECookie),
       {P1,_}=binary:match(Cookie,<<",">>),
  -    ExpirationTime1=binary:part(Cookie,0,P1),
  -    Data=binary:part(Cookie,P1+1,byte_size(Cookie)-20),
  +    ExpirationTimeCookie=binary:part(Cookie,0,P1),
  +    Data=binary:part(Cookie,P1+1,byte_size(Cookie)-(20+P1+1)),
       Hmac=binary:part(Cookie,byte_size(Cookie)-20,20),
  -    check_session_cookie(binary_to_list(ExpirationTime1),Data,Hmac,ExpirationTime,FSessionKey,ServerKey);
  +    check_session_cookie(binary_to_list(ExpirationTimeCookie),Data,Hmac,ExpirationTime,FSessionKey,ServerKey);
   check_session_cookie(_,_,_,_) ->
       {false,[]}.
   check_session_cookie(ExpirationTime1, EData, BHmac,ExpirationTime,FSessionKey,ServerKey) 
     when is_integer(ExpirationTime) , is_list(ServerKey), is_list(ExpirationTime1)->
       ExpTime=list_to_integer(ExpirationTime1),
  -    Key=cookie_gen_key(ExpirationTime1,ServerKey),
  -    Data=cookie_decrypt_data(binary_to_list(EData),Key),
  -    Hmac2=cookie_gen_hmac(ExpirationTime1,Data,FSessionKey(ExpirationTime1),Key),
  -    io:format("~p  ====  ~p",[Hmac2,BHmac]),
  +    Key=gen_key(ExpirationTime1,ServerKey),
  +    Data=decrypt_data(EData,Key),
  +    Hmac2=gen_hmac(ExpirationTime1,Data,FSessionKey(ExpirationTime1),Key),
       if ExpTime<ExpirationTime -> {false,[ExpirationTime1,binary_to_list(Data)]};
          true -> 
   	    if Hmac2==BHmac -> {true,[ExpirationTime1,binary_to_list(Data)]};
  
positive.code: -module(mochiweb_session).
  -export([generate_session_data/4,generate_session_cookie/4,check_session_cookie/4]).
  -export([cookie_encode/1,cookie_decode/1,timestamp_sec/1]).%Useful fuctions for more specific purposes
  -export([cookie_encrypt_data/2,cookie_decrypt_data/2]).
  
  %% @spec generate_session_data(ExpirationTime,Data :: string(),FSessionKey : function(A),ServerKey) -> string()
  %% @doc generates a secure encrypted string convining all the parameters.
  %%      The expritation time is considered in seconds
  generate_session_data(ExpirationTime,Data,FSessionKey,ServerKey) when is_integer(ExpirationTime),is_list(Data), is_function(FSessionKey)->
      BData=list_to_binary(Data),
      ExpTime=integer_to_list(ExpirationTime),
      Key=cookie_gen_key(ExpTime,ServerKey),
      Hmac=cookie_gen_hmac(ExpTime,BData,FSessionKey(integer_to_list(ExpirationTime)),Key),
      io:format("1. ~p~n",[Hmac]),
      EData=cookie_encrypt_data(BData,Key),
      EData2=cookie_decrypt_data(EData,Key),
      io:format("2. ~p - ~p ~n",[BData,EData2]),
      iolist_to_binary([ ExpTime,$,, EData,  Hmac ]).
  
  %% @spec generate_session_data(UserName,ExpirationTime,SessionExtraData,FSessionKey : function(A),ServerKey) -> mochiweb_cookie()
  %% @doc generates a secure encrypted cookie using the generate_session_data function.
  
negative.code: server_key()->%setup function
      ["adfasdfasfs",timestamp_sec(now())].
  
  generate_check_session_cookie([ServerKey,TimeStamp]) ->
      [?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice"]},
  		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice",fun(A)-> A end,ServerKey)
  ,
  					TimeStamp,fun(A)-> A end,ServerKey)),
       ?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and"]},
  		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and",fun(A)-> A end,ServerKey),
  					TimeStamp,fun(A)-> A end,ServerKey)),
       ?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice and bob"]},
  		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice and bob",fun(A)-> A end,ServerKey),
  					TimeStamp,fun(A)-> A end,ServerKey)),
       ?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice jlkjfkjsdfg sdkfjgldsjgl"]},
  		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice jlkjfkjsdfg sdkfjgldsjgl",fun(A)-> A end,ServerKey),
  					TimeStamp,fun(A)-> A end,ServerKey)),
       ?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice .'¡'ç+-$%/(&\""]},
  		   check_session_cookie(generate_session_data(TimeStamp+1000,"alice .'¡'ç+-$%/(&\"",fun(A)-> A end,ServerKey),
  					TimeStamp,fun(A)-> A end,ServerKey)),
       ?_assertEqual({true,[integer_to_list(TimeStamp+1000),"alice456689875"]},
  		   check_session_cookie(generate_session_data(TimeStamp+1000,["alice","456689875"],fun(A)-> A end,ServerKey),
  