This is secretly a question about group cohomology. Suppose we want to compute $\operatorname{Ext}^*_{\mathbb{Z}G}(\mathbb{Z}, \mathbb{Z})$ when $G=\langle g \rangle$ is infinite cyclic and the action on the integers is trivial. We can easily write down a free resolution

$$ 0 \to \mathbb{Z}G(g-1) \to \mathbb{Z}G \to \mathbb{Z} \to 0 $$

and work it out from there: in particular it's clear that $\operatorname{Ext}^n$ vanishes for $n>1$. But we could also try using the bar resolution. On writing this down and applying $\hom_{\mathbb{Z}G} ( -, \mathbb{Z})$ you find that the ext groups are given by the cohomology of the following cocomplex:

$$ \hom_{\mathbb{Z}G} (\mathbb{Z}G, \mathbb{Z}) \to \hom_{\mathbb{Z}G} (\bigoplus_{g \in G} \mathbb{Z}G[g], \mathbb{Z}) \to \hom_{\mathbb{Z}G} (\bigoplus_{g,h \in G} \mathbb{Z}G[g|h],\mathbb{Z}) \to \ldots $$

Of course, $\hom_{\mathbb{Z}G} (\bigoplus_{g \in G} \mathbb{Z}G[g], \mathbb{Z})$ can be identified with the set of maps of sets $G \to \mathbb{Z}$ and so on. On doing this we get that $\operatorname{Ext}^2$ is the kernel of the map

$$\partial_2 : \operatorname{Map}(G\times G, \mathbb{Z}) \to \operatorname{Map}(G\times G\times G, \mathbb{Z}) $$

given by $\partial_2 (f)(g,h,k) = f(h,k) - f(gh,k) + f(g,hk) -f(g,h)$, modulo the image of the map $\partial_1: \operatorname{Map}(G , \mathbb{Z}) \to \operatorname{Map}(G\times G, \mathbb{Z})$ defined by $\partial_1(f)(g,h) = f(h) - f(gh) + f(h)$.

We already know that this cohomology group is zero. But this says exactly that the set of functions $f:G \times G \to \mathbb{Z}$ expressible as $g(x)-g(xy)+g(y)$ is equal to those functions in the kernel of $\partial_2$.

This is equivalent to Denis Serre's answer above - it may look as if there's a discrepancy, but this is fixable by noting that any such f is symmetric.

associativityof the composition is the requirement! I find that very nice. – Mircea Apr 5 '11 at 12:41